Fix incorrect Swagger return type when using IResult #34197
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Title
Fix incorrect Swagger return type when using IResult
PR Description
When a POCO is wrapped in an
IResult
with minimal actions, an incorrect return type is used to determine the default API response format, which results in the response being mapped incorrectly.This then results in the metadata specified by an
[ProducesResponseType]
attribute not being used, resulting in the intended response type not being included in the Swagger documentation.This change resolves this by using
apiResponseType
instead ofresponseType
on line 268 as it is in the surrounding code:aspnetcore/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Lines 262 to 271 in 5577c0d
I discovered this in a sample project that was using the following code where the
ProducesStatusCode()
extension methods add anProducesResponseTypeAttribute
to the endpoint metadata:With the fix this results in the following JSON in the Swagger document:
Without the change, the JSON is: