Skip to content

Commit bd7a372

Browse files
authored
Update to Microsoft.OpenApi v2.0.0-preview.11 (#60761)
* Update to Microsoft.OpenApi v2.0.0-preview.11 * Special case Identity APIs for XML * Revert "Special case Identity APIs for XML" This reverts commit 048240f. * Update method return types
1 parent fb513a5 commit bd7a372

8 files changed

+18
-62
lines changed

eng/Versions.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@
335335
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
336336
<XUnitRunnerVisualStudioVersion>2.8.2</XUnitRunnerVisualStudioVersion>
337337
<MicrosoftDataSqlClientVersion>5.2.2</MicrosoftDataSqlClientVersion>
338-
<MicrosoftOpenApiVersion>2.0.0-preview7</MicrosoftOpenApiVersion>
339-
<MicrosoftOpenApiReadersVersion>2.0.0-preview7</MicrosoftOpenApiReadersVersion>
338+
<MicrosoftOpenApiVersion>2.0.0-preview.11</MicrosoftOpenApiVersion>
339+
<MicrosoftOpenApiReadersVersion>2.0.0-preview.11</MicrosoftOpenApiReadersVersion>
340340
<!-- dotnet tool versions (see also auto-updated DotnetEfVersion property). -->
341341
<DotnetDumpVersion>6.0.322601</DotnetDumpVersion>
342342
<DotnetServeVersion>1.10.93</DotnetServeVersion>

src/OpenApi/src/Comparers/OpenApiTagComparer.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/OpenApi/src/Services/OpenApiDocumentService.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public async Task<OpenApiDocument> GetOpenApiDocumentAsync(IServiceProvider scop
7575
Servers = GetOpenApiServers(httpRequest)
7676
};
7777
document.Paths = await GetOpenApiPathsAsync(document, scopedServiceProvider, operationTransformers, schemaTransformers, cancellationToken);
78-
document.Tags = document.Tags?.Distinct(OpenApiTagComparer.Instance).ToList();
7978
try
8079
{
8180
await ApplyTransformersAsync(document, scopedServiceProvider, cancellationToken);
@@ -327,15 +326,15 @@ private async Task<OpenApiOperation> GetOperationAsync(
327326
=> description.ActionDescriptor.AttributeRouteInfo?.Name ??
328327
description.ActionDescriptor.EndpointMetadata.OfType<IEndpointNameMetadata>().LastOrDefault()?.EndpointName;
329328

330-
private static List<OpenApiTagReference> GetTags(ApiDescription description, OpenApiDocument document)
329+
private static HashSet<OpenApiTagReference> GetTags(ApiDescription description, OpenApiDocument document)
331330
{
332331
var actionDescriptor = description.ActionDescriptor;
333332
if (actionDescriptor.EndpointMetadata?.OfType<ITagsMetadata>().LastOrDefault() is { } tagsMetadata)
334333
{
335-
List<OpenApiTagReference> tags = [];
334+
HashSet<OpenApiTagReference> tags = [];
336335
foreach (var tag in tagsMetadata.Tags)
337336
{
338-
document.Tags ??= [];
337+
document.Tags ??= new HashSet<OpenApiTag>();
339338
document.Tags.Add(new OpenApiTag { Name = tag });
340339
tags.Add(new OpenApiTagReference(tag, document));
341340

@@ -345,9 +344,9 @@ private static List<OpenApiTagReference> GetTags(ApiDescription description, Ope
345344
// If no tags are specified, use the controller name as the tag. This effectively
346345
// allows us to group endpoints by the "resource" concept (e.g. users, todos, etc.)
347346
var controllerName = description.ActionDescriptor.RouteValues["controller"];
348-
document.Tags ??= [];
347+
document.Tags ??= new HashSet<OpenApiTag>();
349348
document.Tags.Add(new OpenApiTag { Name = controllerName });
350-
return [new OpenApiTagReference(controllerName, document)];
349+
return [new(controllerName, document)];
351350
}
352351

353352
private async Task<OpenApiResponses> GetResponsesAsync(

src/OpenApi/src/Services/OpenApiGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,20 @@ private static void GenerateDefaultResponses(Dictionary<int, (Type?, MediaTypeCo
324324
return null;
325325
}
326326

327-
private List<OpenApiTagReference> GetOperationTags(MethodInfo methodInfo, EndpointMetadataCollection metadata)
327+
private HashSet<OpenApiTagReference> GetOperationTags(MethodInfo methodInfo, EndpointMetadataCollection metadata)
328328
{
329329
var metadataList = metadata.GetOrderedMetadata<ITagsMetadata>();
330330
var document = new OpenApiDocument();
331331

332332
if (metadataList.Count > 0)
333333
{
334-
var tags = new List<OpenApiTagReference>();
334+
var tags = new HashSet<OpenApiTagReference>();
335335

336336
foreach (var metadataItem in metadataList)
337337
{
338338
foreach (var tag in metadataItem.Tags)
339339
{
340-
document.Tags ??= [];
340+
document.Tags ??= new HashSet<OpenApiTag>();
341341
document.Tags.Add(new OpenApiTag { Name = tag });
342342
tags.Add(new OpenApiTagReference(tag, document));
343343
}
@@ -359,7 +359,7 @@ private List<OpenApiTagReference> GetOperationTags(MethodInfo methodInfo, Endpoi
359359
controllerName = _environment?.ApplicationName ?? string.Empty;
360360
}
361361

362-
document.Tags ??= [];
362+
document.Tags ??= new HashSet<OpenApiTag>();
363363
document.Tags.Add(new OpenApiTag { Name = controllerName });
364364
return [new(controllerName, document)];
365365
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ await ValidateOpenApiDocumentAsync(responseBodyStream, document =>
235235
private static async Task ValidateOpenApiDocumentAsync(MemoryStream documentStream, Action<OpenApiDocument> action, string format = "json")
236236
{
237237
documentStream.Position = 0;
238-
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
239-
var result = await OpenApiDocument.LoadAsync(documentStream, format);
238+
var readerSettings = new OpenApiReaderSettings();
239+
readerSettings.AddYamlReader();
240+
var result = await OpenApiDocument.LoadAsync(documentStream, format, readerSettings);
240241
Assert.Empty(result.Diagnostic.Errors);
241242
action(result.Document);
242243
}

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/OpenApiDocumentIntegrationTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
[UsesVerify]
1212
public sealed class OpenApiDocumentIntegrationTests(SampleAppFixture fixture) : IClassFixture<SampleAppFixture>
1313
{
14-
private static Regex DateTimeRegex() => new(
15-
@"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}[+-]\d{2}:\d{2}",
16-
RegexOptions.Compiled);
17-
1814
[Theory]
1915
[InlineData("v1", OpenApiSpecVersion.OpenApi3_0)]
2016
[InlineData("v2", OpenApiSpecVersion.OpenApi3_0)]
@@ -42,7 +38,6 @@ public async Task VerifyOpenApiDocument(string documentName, OpenApiSpecVersion
4238
var outputDirectory = Path.Combine(baseSnapshotsDirectory, version.ToString());
4339
await Verifier.Verify(json)
4440
.UseDirectory(outputDirectory)
45-
.ScrubLinesWithReplace(line => DateTimeRegex().Replace(line, "[datetime]"))
4641
.UseParameters(documentName);
4742
}
4843
}

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@
375375
"dateTimeType": {
376376
"type": "string",
377377
"format": "date-time",
378-
"example": "[datetime]"
378+
"example": "2022-01-01T00:00:00Z"
379379
},
380380
"dateOnlyType": {
381381
"type": "string",
382382
"format": "date",
383-
"example": "[datetime]"
383+
"example": "2022-01-01"
384384
}
385385
}
386386
}

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@
375375
"dateTimeType": {
376376
"type": "string",
377377
"format": "date-time",
378-
"example": "[datetime]"
378+
"example": "2022-01-01T00:00:00Z"
379379
},
380380
"dateOnlyType": {
381381
"type": "string",
382382
"format": "date",
383-
"example": "[datetime]"
383+
"example": "2022-01-01"
384384
}
385385
}
386386
}

0 commit comments

Comments
 (0)