Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions src/OpenApi/build/Microsoft.AspNetCore.OpenApi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
<ItemGroup>
<AdditionalFiles
Include="@(ReferencePath->'%(RootDir)%(Directory)%(Filename).xml')"
Condition="'%(ReferencePath.Extension)' == '.dll' AND
Exists('%(ReferencePath.RootDir)%(ReferencePath.Directory)%(ReferencePath.Filename).xml') AND
('%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference')"
Condition="
Copy link
Member

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?

Copy link
Member Author

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.

'%(ReferencePath.Extension)' == '.dll' AND
Exists('%(ReferencePath.RootDir)%(ReferencePath.Directory)%(ReferencePath.Filename).xml') AND
('%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' OR
'%(ReferencePath.FileName)' == 'Microsoft.AspNetCore.Identity')"
KeepMetadata="Identity" />
</ItemGroup>
</Target>
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 ISet<OpenApiTagReference> GetTags(ApiDescription description, OpenApiDocument document)
Copy link
Member

Choose a reason for hiding this comment

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

extreme nit: Generally for private/internal methods we can return the concrete type instead of an interface, this allows for optimizations at the usage site. I know the return values here are just set on an OpenAPI type, but just a general pattern.

{
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));

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 HashSet<OpenApiTagReference> { new(controllerName, document) };
}

private async Task<OpenApiResponses> GetResponsesAsync(
Expand Down
13 changes: 8 additions & 5 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 ISet<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,9 +359,12 @@ 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)];
return new HashSet<OpenApiTagReference>
{
new(controllerName, document)
};
}

private List<IOpenApiParameter> GetOpenApiParameters(MethodInfo methodInfo, RoutePattern pattern, bool disableInferredBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void VerifiesTargetGeneratesXmlFiles()
// Captures ProjectReferences and PackageReferences in project.
var identities = additionalFiles.Select(x => x["Identity"]).ToArray();
Assert.Collection(identities,
x => Assert.EndsWith("ClassLibrary.xml", x)
x => Assert.EndsWith("ClassLibrary.xml", x),
x => Assert.EndsWith("Microsoft.AspNetCore.Identity.xml", x)
);
}

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