-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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 ISet<OpenApiTagReference> GetTags(ApiDescription description, OpenApiDocument document) | ||
|
||
{ | ||
var actionDescriptor = description.ActionDescriptor; | ||
if (actionDescriptor.EndpointMetadata?.OfType<ITagsMetadata>().LastOrDefault() is { } tagsMetadata) | ||
{ | ||
List<OpenApiTagReference> tags = []; | ||
ISet<OpenApiTagReference> tags = new HashSet<OpenApiTagReference>(); | ||
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)); | ||
|
||
|
@@ -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 HashSet<OpenApiTagReference> { new(controllerName, document) }; | ||
} | ||
|
||
private async Task<OpenApiResponses> GetResponsesAsync( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)] | ||
|
@@ -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]")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this that bug I reported last week? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! It got fixed in preview9 or preview10 I believe. |
||
.UseParameters(documentName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment here for what we're doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny story I have to revert this because of #60783 but I will be sure to add a comment once I've recolved that issue.