Improve OpenAPI/Swagger response metadata for returned IResults
See original GitHub issueToday, when you return an IResult
from a minimal action, you lose all metadata about the type of the response (see https://github.com/dotnet/aspnetcore/pull/33433). You can add the metadata back with something like [ProducesResponseType(typeof(Person), 201]
, but in many cases the response type could be inferred from the IResult
implementation if we designed a way for this to work.
The most obvious idea is to do like ActionResult<TValue>
though implicit conversions with interfaces might make this tricky.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Create responses in Minimal API applications
Learn how to create responses for minimal APIs in ASP. ... This alternative is better than returning IResult because the generic union types ......
Read more >Open API support for ASP.NET Core Minimal API
This article will discuss about implementing Open API (Swagger) for ASP.NET Core 6.0 minimal API. Today I saw one video from Maria Naggaga ......
Read more >Enriched Web API Documentation using Swagger/OpenAPI in ...
Testing tools to execute API requests and validate responses on the fly. ... Possible actions to improve the default OpenAPI documentation.
Read more >Handling API validation with OpenAPI (Swagger) ...
Handling API validation with OpenAPI (Swagger) documents in NodeJS. ... It has two responses, a 200 that returns an array of records, ...
Read more >In Python's FastAPI autogenerated OpenAPI/Swagger ...
FastAPI generates automatic swagger/openapi documentation. In the tutorial at https://fastapi.tiangolo.com/tutorial/response-status-code there's ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Strawman set of extension methods for setting endpoint metadata. Additional context provided in the doc/code comments. These methods and their new supporting types (where required) can also be seen in the playground repo.
Design considerations
Further details that were considered during the design of this proposal:
Microsoft.AspNetCore.Http.Results
, e.g.ProducesCreated
,ProducesConflict
,ProducesNotFound
, etc. As the eventual goal is for the experience to determine the correct information RE what endpoints produce and set the relevant metadata by default, thus requiring these methods to not be required to be called in the vast majority of cases, it was decided that we shouldn’t create such a large set of API surface area only to have it not be used (generally) in the future.Produces<ProblemDetails>(500, "application/problem+json")
andProduces<HttpValidationProblemDetails>(400, "application/problem+json")
. For this reason it was decided that higher level methods for problem details should be included, e.g.ProducesProblem
,ProducesValidationProblem
. These offer a nice symmetry with theResults.Problem
andResults.ValidationProblem
results methods too.Also I do think at some point we’ll enable hopefully much of this as a convention/automatically so that one doesn’t need to describe the response shape manually at all, e.g. via a source generator.