-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add OpenAPI/Swagger support for minimal actions #33433
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
Conversation
src/Mvc/Mvc.ApiExplorer/src/EndpointMethodInfoApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
&& routeEndpoint.Metadata.GetMetadata<MethodInfo>() is { } methodInfo | ||
&& routeEndpoint.Metadata.GetMetadata<IHttpMethodMetadata>() is { } httpMethodMetadata) | ||
{ | ||
// REVIEW: Should we add an ApiDescription for endpoints without IHttpMethodMetadata? Swagger doesn't handle |
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.
Interesting q - MVC does add an entry for items that do not specify a method constraint (with a null value), so maybe it's fine to add one:
aspnetcore/src/Mvc/Mvc.ApiExplorer/src/DefaultApiDescriptionProvider.cs
Lines 341 to 351 in 44bcd96
private IEnumerable<string?> GetHttpMethods(ControllerActionDescriptor action) | |
{ | |
if (action.ActionConstraints != null && action.ActionConstraints.Count > 0) | |
{ | |
return action.ActionConstraints.OfType<HttpMethodActionConstraint>().SelectMany(c => c.HttpMethods); | |
} | |
else | |
{ | |
return new string?[] { null }; | |
} | |
} |
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.
I tried null initially since ApiDescription.HttpMethod
is indeed nullable, but I get this when trying this with Swashbuckle 5.6.3.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Ambiguous HTTP method for action - . Actions require an explicit HttpMethod binding for Swagger/OpenAPI 3.0
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f0+0x76
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000ef+0x60
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000ed+0xe0
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) in Swashbuckle.AspNetCore.Swagger.dll:token 0x6000009+0xa9
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application) in Microsoft.AspNetCore.Server.Kestrel.Core.dll:token 0x6000a9f+0x1b8
Is there a workaround?
src/Mvc/Mvc.ApiExplorer/src/EndpointMethodInfoApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
src/Mvc/Mvc.ApiExplorer/src/EndpointMethodInfoApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
OH SO EXCITING |
src/Mvc/Mvc.ApiExplorer/src/EndpointMethodInfoApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
// For example,w "<>c" is a "declaring" type the C# compiler will generate without the attribute for a top-level lambda | ||
// REVIEW: Is there a better way to do this? | ||
private static bool IsCompilerGenerated(Type type) => | ||
Attribute.IsDefined(type, typeof(CompilerGeneratedAttribute)) || type.Name.StartsWith('<'); |
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.
@jaredpar Is there a better way to do this?
3f3e634
to
3f9451c
Compare
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
/backport to release/6.0-preview6 |
Started backporting to release/6.0-preview6: https://github.com/dotnet/aspnetcore/actions/runs/941202939 |
API Review: That would make MinimalActions more of a public name, whereas right now it's mostly a code-name.
|
Addresses #30662