Skip to content

Commit

Permalink
fix: Resolved conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 5, 2024
1 parent c80b407 commit 7e0f1e0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 69 deletions.
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ private static string ConvertByteArrayToString(byte[] hash)
string relativePath = OpenApiConstants.ComponentsSegment + reference.Type.GetDisplayName() + "/" + reference.Id;

uriLocation = useExternal
? Workspace.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath
? Workspace?.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath
: BaseUri + relativePath;
}

return Workspace.ResolveReference<IOpenApiReferenceable>(uriLocation);
return Workspace?.ResolveReference<IOpenApiReferenceable>(uriLocation);
}

/// <summary>
Expand Down Expand Up @@ -628,9 +628,9 @@ public static ReadResult Parse(string input,

internal class FindSchemaReferences : OpenApiVisitorBase
{
private Dictionary<string, OpenApiSchema> Schemas;
private Dictionary<string, OpenApiSchema> Schemas = new();

public static void ResolveSchemas(OpenApiComponents components, Dictionary<string, OpenApiSchema> schemas)
public static void ResolveSchemas(OpenApiComponents? components, Dictionary<string, OpenApiSchema> schemas)
{
var visitor = new FindSchemaReferences();
visitor.Schemas = schemas;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,21 @@ public void RemoveAnyOfAndOneOfFromSchema()
var walker = new OpenApiWalker(powerShellFormatter);
walker.Walk(openApiDocument);

var testSchema = openApiDocument.Components.Schemas["TestSchema"];
var averageAudioDegradationProperty = testSchema.Properties["averageAudioDegradation"];
var defaultPriceProperty = testSchema.Properties["defaultPrice"];
var testSchema = openApiDocument.Components?.Schemas?["TestSchema"];
var averageAudioDegradationProperty = testSchema?.Properties["averageAudioDegradation"];
var defaultPriceProperty = testSchema?.Properties["defaultPrice"];

// Assert
Assert.Null(averageAudioDegradationProperty.AnyOf);
Assert.Equal("number", averageAudioDegradationProperty.Type);
Assert.Equal("float", averageAudioDegradationProperty.Format);
Assert.True(averageAudioDegradationProperty.Nullable);
Assert.Null(defaultPriceProperty.OneOf);
Assert.Equal("number", defaultPriceProperty.Type);
Assert.Equal("double", defaultPriceProperty.Format);
Assert.NotNull(openApiDocument.Components);
Assert.NotNull(openApiDocument.Components.Schemas);
Assert.NotNull(testSchema);
Assert.Null(averageAudioDegradationProperty?.AnyOf);
Assert.Equal("number", averageAudioDegradationProperty?.Type);
Assert.Equal("float", averageAudioDegradationProperty?.Format);
Assert.True(averageAudioDegradationProperty?.Nullable);
Assert.Null(defaultPriceProperty?.OneOf);
Assert.Equal("number", defaultPriceProperty?.Type);
Assert.Equal("double", defaultPriceProperty?.Format);
Assert.NotNull(testSchema.AdditionalProperties);
}

Expand All @@ -83,12 +86,12 @@ public void ResolveFunctionParameters()
var walker = new OpenApiWalker(powerShellFormatter);
walker.Walk(openApiDocument);

var idsParameter = openApiDocument.Paths["/foo"].Operations[OperationType.Get].Parameters.Where(static p => p.Name == "ids").FirstOrDefault();
var idsParameter = openApiDocument.Paths?["/foo"].Operations[OperationType.Get].Parameters?.Where(static p => p.Name == "ids").FirstOrDefault();

// Assert
Assert.Null(idsParameter?.Content);
Assert.NotNull(idsParameter?.Schema);
Assert.Equal("array", idsParameter?.Schema.Type);
Assert.Equal("array", idsParameter.Schema.Type);
}

private static OpenApiDocument GetSampleOpenApiDocument()
Expand Down
Loading

0 comments on commit 7e0f1e0

Please sign in to comment.