-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support multiple response types with the same status code in ApiExplorer #55412
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
Comments
FYI @captainsafia |
@keahpeters Thanks for reporting this issue! I'll take a look at the feasibility of making a change to ApiResponseProvider, considering that OpenApi now supports Particular for attribute-based applications, we tend to follow the model that |
I'll vote this up. Here is my sample scenario: consider this API endpoint [JsonDerivedType(typeof(ParentWithChildrenDto))]
public record ParentDto(int Id);
public record ParentWithChildrenDto(int Id, ChildDto[] Children) : ParentDto(Id);
public record ChildDto(int Id, string Name); then when [HttpGet]
[ProduceResponseType<ParentDto>(StatusCodes.Status200OK)]
[ProduceResponseType<ParentWithChildrenDto>(StatusCodes.Status200OK)] |
The openapi OneOf can be utilized by inheritance (at least via Swashbuckle
|
We didn't get around to doing this in .NET 9 unfortunately. I'm closing this issue in favor of #56177 which tracks a similar request. Giving a thumbs up on that issue is a good way to indicate interest and help us prioritize it in the future. |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
When using the
ProducesResponseType
attribute to specify multiple response types with the same status code only the last specified status code will be exposed. This limitation affects scenarios where an endpoint might return different types for the same HTTP status code based on business logic. For example in the following theFoo
type would not be included in the response metadata.This is due to the status code being used as the key in the results dictionary when reading the response metadata https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.ApiExplorer/src/ApiResponseTypeProvider.cs#L210.
Describe the solution you'd like
All specified response types to be included in
SupportedResponseTypes
when there are multiple response types with the same status code.Additional context
Related to domaindrivendev/Swashbuckle.AspNetCore#2743.
The text was updated successfully, but these errors were encountered: