Skip to content

Update to Microsoft.OpenApi v2.0.0-preview.11 #60761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
<XUnitRunnerVisualStudioVersion>2.8.2</XUnitRunnerVisualStudioVersion>
<MicrosoftDataSqlClientVersion>5.2.2</MicrosoftDataSqlClientVersion>
<MicrosoftOpenApiVersion>2.0.0-preview7</MicrosoftOpenApiVersion>
<MicrosoftOpenApiReadersVersion>2.0.0-preview7</MicrosoftOpenApiReadersVersion>
<MicrosoftOpenApiVersion>2.0.0-preview.11</MicrosoftOpenApiVersion>
<MicrosoftOpenApiReadersVersion>2.0.0-preview.11</MicrosoftOpenApiReadersVersion>
<!-- dotnet tool versions (see also auto-updated DotnetEfVersion property). -->
<DotnetDumpVersion>6.0.322601</DotnetDumpVersion>
<DotnetServeVersion>1.10.93</DotnetServeVersion>
Expand Down
39 changes: 0 additions & 39 deletions src/OpenApi/src/Comparers/OpenApiTagComparer.cs

This file was deleted.

11 changes: 5 additions & 6 deletions src/OpenApi/src/Services/OpenApiDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public async Task<OpenApiDocument> GetOpenApiDocumentAsync(IServiceProvider scop
Servers = GetOpenApiServers(httpRequest)
};
document.Paths = await GetOpenApiPathsAsync(document, scopedServiceProvider, operationTransformers, schemaTransformers, cancellationToken);
document.Tags = document.Tags?.Distinct(OpenApiTagComparer.Instance).ToList();
try
{
await ApplyTransformersAsync(document, scopedServiceProvider, cancellationToken);
Expand Down Expand Up @@ -327,15 +326,15 @@ private async Task<OpenApiOperation> GetOperationAsync(
=> description.ActionDescriptor.AttributeRouteInfo?.Name ??
description.ActionDescriptor.EndpointMetadata.OfType<IEndpointNameMetadata>().LastOrDefault()?.EndpointName;

private static List<OpenApiTagReference> GetTags(ApiDescription description, OpenApiDocument document)
private static HashSet<OpenApiTagReference> GetTags(ApiDescription description, OpenApiDocument document)
{
var actionDescriptor = description.ActionDescriptor;
if (actionDescriptor.EndpointMetadata?.OfType<ITagsMetadata>().LastOrDefault() is { } tagsMetadata)
{
List<OpenApiTagReference> tags = [];
HashSet<OpenApiTagReference> tags = [];
foreach (var tag in tagsMetadata.Tags)
{
document.Tags ??= [];
document.Tags ??= new HashSet<OpenApiTag>();
document.Tags.Add(new OpenApiTag { Name = tag });
tags.Add(new OpenApiTagReference(tag, document));

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

private async Task<OpenApiResponses> GetResponsesAsync(
Expand Down
8 changes: 4 additions & 4 deletions src/OpenApi/src/Services/OpenApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,20 @@ private static void GenerateDefaultResponses(Dictionary<int, (Type?, MediaTypeCo
return null;
}

private List<OpenApiTagReference> GetOperationTags(MethodInfo methodInfo, EndpointMetadataCollection metadata)
private HashSet<OpenApiTagReference> GetOperationTags(MethodInfo methodInfo, EndpointMetadataCollection metadata)
{
var metadataList = metadata.GetOrderedMetadata<ITagsMetadata>();
var document = new OpenApiDocument();

if (metadataList.Count > 0)
{
var tags = new List<OpenApiTagReference>();
var tags = new HashSet<OpenApiTagReference>();

foreach (var metadataItem in metadataList)
{
foreach (var tag in metadataItem.Tags)
{
document.Tags ??= [];
document.Tags ??= new HashSet<OpenApiTag>();
document.Tags.Add(new OpenApiTag { Name = tag });
tags.Add(new OpenApiTagReference(tag, document));
}
Expand All @@ -359,7 +359,7 @@ private List<OpenApiTagReference> GetOperationTags(MethodInfo methodInfo, Endpoi
controllerName = _environment?.ApplicationName ?? string.Empty;
}

document.Tags ??= [];
document.Tags ??= new HashSet<OpenApiTag>();
document.Tags.Add(new OpenApiTag { Name = controllerName });
return [new(controllerName, document)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ await ValidateOpenApiDocumentAsync(responseBodyStream, document =>
private static async Task ValidateOpenApiDocumentAsync(MemoryStream documentStream, Action<OpenApiDocument> action, string format = "json")
{
documentStream.Position = 0;
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
var result = await OpenApiDocument.LoadAsync(documentStream, format);
var readerSettings = new OpenApiReaderSettings();
readerSettings.AddYamlReader();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much nicer than that static registration.

var result = await OpenApiDocument.LoadAsync(documentStream, format, readerSettings);
Assert.Empty(result.Diagnostic.Errors);
action(result.Document);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
[UsesVerify]
public sealed class OpenApiDocumentIntegrationTests(SampleAppFixture fixture) : IClassFixture<SampleAppFixture>
{
private static Regex DateTimeRegex() => new(
@"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}[+-]\d{2}:\d{2}",
RegexOptions.Compiled);

[Theory]
[InlineData("v1", OpenApiSpecVersion.OpenApi3_0)]
[InlineData("v2", OpenApiSpecVersion.OpenApi3_0)]
Expand Down Expand Up @@ -42,7 +38,6 @@ public async Task VerifyOpenApiDocument(string documentName, OpenApiSpecVersion
var outputDirectory = Path.Combine(baseSnapshotsDirectory, version.ToString());
await Verifier.Verify(json)
.UseDirectory(outputDirectory)
.ScrubLinesWithReplace(line => DateTimeRegex().Replace(line, "[datetime]"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this that bug I reported last week?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! It got fixed in preview9 or preview10 I believe.

.UseParameters(documentName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,12 @@
"dateTimeType": {
"type": "string",
"format": "date-time",
"example": "[datetime]"
"example": "2022-01-01T00:00:00Z"
},
"dateOnlyType": {
"type": "string",
"format": "date",
"example": "[datetime]"
"example": "2022-01-01"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,12 @@
"dateTimeType": {
"type": "string",
"format": "date-time",
"example": "[datetime]"
"example": "2022-01-01T00:00:00Z"
},
"dateOnlyType": {
"type": "string",
"format": "date",
"example": "[datetime]"
"example": "2022-01-01"
}
}
}
Expand Down
Loading