Skip to content

Commit

Permalink
Changes per review
Browse files Browse the repository at this point in the history
  • Loading branch information
hwoodiwiss committed Apr 14, 2024
1 parent dd6c603 commit b4ecaaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ private OpenApiOperation GenerateOperation(ApiDescription apiDescription, Schema
RequestBody = GenerateRequestBody(apiDescription, schemaRepository),
Responses = GenerateResponses(apiDescription, schemaRepository),
Deprecated = apiDescription.CustomAttributes().OfType<ObsoleteAttribute>().Any(),
#if NET7_0_OR_GREATER
Summary = GenerateSummary(apiDescription),
Description = GenerateDescription(apiDescription),
#endif
};

apiDescription.TryGetMethodInfo(out MethodInfo methodInfo);
Expand Down Expand Up @@ -656,32 +658,18 @@ private OpenApiMediaType CreateResponseMediaType(ModelMetadata modelMetadata, Sc
new KeyValuePair<string, string>("default", "Error")
};

private string GenerateSummary(ApiDescription apiDescription)
{
string operationSummary = null;
#if NET7_0_OR_GREATER
operationSummary = apiDescription
.ActionDescriptor
?.EndpointMetadata
private string GenerateSummary(ApiDescription apiDescription) =>
apiDescription.ActionDescriptor?.EndpointMetadata
?.OfType<IEndpointSummaryMetadata>()
.Select(s => s.Summary)
.LastOrDefault();
#endif
return operationSummary;
}

private string GenerateDescription(ApiDescription apiDescription)
{
string operationDescription = null;
#if NET7_0_OR_GREATER
operationDescription = apiDescription
.ActionDescriptor
?.EndpointMetadata
private string GenerateDescription(ApiDescription apiDescription) =>
apiDescription.ActionDescriptor?.EndpointMetadata
?.OfType<IEndpointDescriptionMetadata>()
.Select(s => s.Description)
.LastOrDefault();
#endif
return operationDescription;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public void GetSwagger_UseProvidedOpenApiOperation_IfExistsInMetadata()
var actionDescriptor = new ActionDescriptor
{
EndpointMetadata = new List<object>()
{
new OpenApiOperation
{
new OpenApiOperation
{
OperationId = "OperationIdSetInMetadata",
Parameters = new List<OpenApiParameter>()
Expand Down Expand Up @@ -199,7 +199,7 @@ public void GetSwagger_GenerateProducesSchemas_ForProvidedOpenApiOperation()
{
Content = new Dictionary<string, OpenApiMediaType>()
{
["application/someMediaType"] = new()
["application/someMediaType"] = new()
}
}
}
Expand Down Expand Up @@ -965,6 +965,7 @@ public void GetSwagger_CanReadTagsFromMetadata()
Assert.Equal(new[] { "Some", "Tags", "Here" }, document.Paths["/resource"].Operations[OperationType.Post].Tags.Select(t => t.Name));
}

#if NET7_0_OR_GREATER
[Fact]
public void GetSwagger_CanReadEndpointSummaryFromMetadata()
{
Expand Down Expand Up @@ -1012,6 +1013,7 @@ public void GetSwagger_CanReadEndpointDescriptionFromMetadata()

Assert.Equal("A Test Description", document.Paths["/resource"].Operations[OperationType.Post].Description);
}
#endif

[Fact]
public void GetSwagger_SupportsOption_ConflictingActionsResolver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit b4ecaaa

Please sign in to comment.