Skip to content

Commit ca25dfb

Browse files
committed
Address feedback
1 parent df3fe64 commit ca25dfb

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/OpenApi/src/Services/OpenApiDocumentService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public async Task<OpenApiDocument> GetOpenApiDocumentAsync(IServiceProvider scop
8888
document.Workspace.RegisterComponents(document);
8989
if (document.Components?.Schemas is not null)
9090
{
91-
document.Components.Schemas = document.Components.Schemas.OrderBy(schema => schema.Key).ToDictionary();
91+
document.Components.Schemas = new SortedDictionary<string, OpenApiSchema>(document.Components.Schemas);
9292
}
9393
return document;
9494
}

src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ internal static OpenApiSchema ResolveReferenceForSchema(OpenApiDocument document
196196
schema.Not = ResolveReferenceForSchema(document, schema.Not);
197197
}
198198

199-
// Handle schemas where the references have been inline by the JsonSchemaExporter. In this case,
199+
// Handle schemas where the references have been inlined by the JsonSchemaExporter. In this case,
200200
// the `#` ID is generated by the exporter since it has no base document to baseline against. In this
201201
// case we we want to replace the reference ID with the schema ID that was generated by the
202202
// `CreateSchemaReferenceId` method in the OpenApiSchemaService.

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiEndpointRouteBuilderExtensionsTests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.OpenApi.Models;
1313
using Microsoft.OpenApi.Readers;
1414
using System.Text;
15+
using Microsoft.OpenApi.Reader;
1516

1617
public class OpenApiEndpointRouteBuilderExtensionsTests : OpenApiDocumentServiceTestBase
1718
{
@@ -67,7 +68,7 @@ public async Task MapOpenApi_ReturnsRenderedDocument()
6768

6869
// Assert
6970
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
70-
ValidateOpenApiDocument(responseBodyStream, document =>
71+
await ValidateOpenApiDocumentAsync(responseBodyStream, document =>
7172
{
7273
Assert.Equal("OpenApiEndpointRouteBuilderExtensionsTests | v1", document.Info.Title);
7374
Assert.Equal("1.0.0", document.Info.Version);
@@ -102,11 +103,11 @@ public async Task MapOpenApi_ReturnsDefaultDocumentIfNoNameProvided(string expec
102103
// String check to validate that generated document starts with YAML syntax
103104
Assert.Equal(isYaml, responseString.StartsWith("openapi: '3.1.1'", StringComparison.OrdinalIgnoreCase));
104105
responseBodyStream.Position = 0;
105-
ValidateOpenApiDocument(responseBodyStream, document =>
106+
await ValidateOpenApiDocumentAsync(responseBodyStream, document =>
106107
{
107108
Assert.Equal("OpenApiEndpointRouteBuilderExtensionsTests | v1", document.Info.Title);
108109
Assert.Equal("1.0.0", document.Info.Version);
109-
});
110+
}, isYaml ? "yaml" : "json");
110111
}
111112

112113
[Fact]
@@ -163,16 +164,18 @@ public async Task MapOpenApi_ReturnsDocumentIfNameProvidedInQuery(string expecte
163164
// String check to validate that generated document starts with YAML syntax
164165
Assert.Equal(isYaml, responseString.StartsWith("openapi: '3.1.1'", StringComparison.OrdinalIgnoreCase));
165166
responseBodyStream.Position = 0;
166-
ValidateOpenApiDocument(responseBodyStream, document =>
167+
await ValidateOpenApiDocumentAsync(responseBodyStream, document =>
167168
{
168169
Assert.Equal($"OpenApiEndpointRouteBuilderExtensionsTests | {documentName}", document.Info.Title);
169170
Assert.Equal("1.0.0", document.Info.Version);
170-
});
171+
}, isYaml ? "yaml" : "json");
171172
}
172173

173-
private static async void ValidateOpenApiDocument(MemoryStream documentStream, Action<OpenApiDocument> action)
174+
private static async Task ValidateOpenApiDocumentAsync(MemoryStream documentStream, Action<OpenApiDocument> action, string format = "json")
174175
{
175-
var result = await OpenApiDocument.LoadAsync(documentStream, "json");
176+
documentStream.Position = 0;
177+
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
178+
var result = await OpenApiDocument.LoadAsync(documentStream, format);
176179
Assert.Empty(result.OpenApiDiagnostic.Errors);
177180
action(result.OpenApiDocument);
178181
}

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.ParameterSchemas.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ await VerifyOpenApiDocument(builder, document =>
7070
{
7171
var operation = document.Paths["/api/{id}"].Operations[OperationType.Get];
7272
var parameter = Assert.Single(operation.Parameters);
73-
Assert.Equal( schemaType, parameter.Schema.Type);
73+
Assert.Equal(schemaType, parameter.Schema.Type);
7474
Assert.Equal(schemaFormat, parameter.Schema.Format);
7575
Assert.False(parameter.Schema.Nullable);
7676
});

0 commit comments

Comments
 (0)