Description
Is your feature request related to a problem? Please describe.
Hi, I am using the new minimal hosting model with dotnet 6 and I set up my endpoints like this:
endpoints.MapPost("user/createWithList", ExecutionDelegate).WithTags("user");
Is there a way to set the summary of the route, so right next to the route -> underlined with red?
Is there a way to set the extended description of the route, so below the http method, in this case POST, and above the parameters section -> marked by the red arrow?
I already checked and there seem to only be the WithTags method or the AddMetaData where you could add EndpointNameMetadata
I think this feature is essential for providing a well structured and helpful api documentation.
Describe the solution you'd like
I would like to have the option to add the description either by having a dedicated method for that, so:
endpoints.MapPost("user/createWithList", ExecutionDelegate).WithTags("user").WithDescription("This endpoints lets you create users for ...");
or to have attributes like the EndpointNameMetadata f.e. EndpointDescriptionMetadata
which can be used to set the OpenApi description of that route and be passed to the WithMetadata()
method
Activity
rafikiassumani-msft commentedon Oct 28, 2021
Triage: We are planning to fix this as part of .NET7 issue #37098
nilzzzzzz commentedon Oct 28, 2021
@rafikiassumani-msft thanks for the update. Is there any entry point where we could implement the functionality to add an endpoint description ourself till the gap is potentially closed in .NET7 ? Any hint would be highly appreciated.
martincostello commentedon Oct 29, 2021
This should light up when using
SwaggerOperationAttribute
in Swashbuckle.AspNetCore for .NET 6 once this change is merged and released: domaindrivendev/Swashbuckle.AspNetCore#2215.You can see some examples of working around it in this repo of mine: https://github.com/martincostello/api/search?q=SwaggerOperationAttribute
nilzzzzzz commentedon Oct 29, 2021
@martincostello bam! thank you! I already thought we need to move back to mvc controllers. ;)
captainsafia commentedon Feb 7, 2022
Background and Motivation
The OpenAPI schema provides support for annotating properties with summaries, descriptions, and examples.
value
that represents an inline implementation of the type or anexternalValue
which is an external reference to an example.value
andexternalValue
are mutually exclusive.This PR introduces support for these annotations in minimal APIs via declarative and imperative approaches. It does not modify any of the logic in MVC though. That is supported by XML-doc parsing support in Swashbuckle which pulls the data above from XML docs on an action/endpoint. We are tracking #39927 to look at supporting this pattern for minimal APIs as well.
Proposed API
Description and Summary
ExampleMetadata
Extension Methods
ApiExplorer Changes
Usage Examples
Alternative Designs and Considerations
WithRequestExample
and only allowing theRequestBody
to be annotated via an attribute.IExampleMetadata<T>
to support a better experience for the developer.DescriptionAttribute
and opt for respectingSystem.ComponentModel.DescriptionAttribute
instead?WithParameterExample
extension method for defining examples for parameters with types that can't be initialized as constants in an attribute?WithParameterX
,WithResponseX
pattern?captainsafia commentedon Feb 9, 2022
We held a little API review for this and decided to go in a different direction with this implementation.
Supporting
Description
andSummary
on endpoints is very sensible and fine, but the ahem scope creep ahem I introduced by exploring the requirements to add support for parameter and response-type specific properties introduces a couple of thorny questions:IExampleMetadata
outlined above aligns very closely with the OpenAPI spec and gets us into tricky territory with having to align our APIs with the evolution of the OpenAPI spec.IExampleMetadata
, where do we end?With that in mind, we've opened #40084 to examine creating a unified extension method for endpoints that allows modifying all aspects of an API description.
And, we've limited the scope of this change to what was strictly in the original issue, supporting descriptions and summaries in endpoints. So now the new API we're taking through review is:
Interfaces and Classes
Extension Methods
Usage Examples