Skip to content

ProducesResponseType(typeof(void), ...) causes ApiExplorer to indicate the return type is ProblemDetails #7874

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

Closed
Tracked by #27889
kingmotley opened this issue Feb 22, 2019 · 6 comments · Fixed by #30509
Assignees
Labels
affected-medium This issue impacts approximately half of our customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates breaking-change This issue / pr will introduce a breaking change, when resolved / merged. bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed severity-major This label is used by an internal tool
Milestone

Comments

@kingmotley
Copy link

kingmotley commented Feb 22, 2019

Describe the bug

ApiExplorer/ProducesResponseType exposes incorrect value when the return type is void. It seems to override any attempt to indicate that the response produces no results/body with ProblemDetails.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core 2.2
  2. Apply the following attribute to an ApiController:
    [ProducesResponseType(typeof(void), (int)HttpStatusCode.Unauthorized)
  3. ApiExplorer indicates the return type is ProblemDetails.

Expected behavior

ApiExplorer should say the return type is void.

@kingmotley
Copy link
Author

Originally reported to Swashbuckle team here: domaindrivendev/Swashbuckle.AspNetCore#1043

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Feb 25, 2019
@pranavkm pranavkm added the bug This issue describes a behavior which is not expected - a bug. label Feb 26, 2019
@pranavkm
Copy link
Contributor

I'm marking this as a bug to see if there's interest in making this work out of the box. For 2.2, you could do this by specifying a ProducesErrorResponseAttribute e.g.

[ProducesErrorResponseType(typeof(void)]
[ProducesResponseType(StatusCodes.Unauthorized)]
public IActionResult Method() => {}

That said, do you actually see an empty body in the response? ApiController adds a result filter by default that should turn your 401 unauthorized status code result to one with a ProblemDetails body.

@kingmotley
Copy link
Author

Sorry, was away for a week. Yes, the actual body is empty on a 401, which is what I would expect (probably). Swagger shows that it returns a ProblemDetails, but it does not in actual use.

Adding [ProducesErrorResponseType(typeof(void))] does appear to change the 401 to a void in swagger.

@danroth27
Copy link
Member

@pranavkm Is there anything actionable here then?

@LiangZugeng
Copy link

We are using NSwag to produce TypeScript client classes and we encountered this issue, to summarize:

  1. [ProducesErrorResponseType(typeof(void))] works expectedly
  2. [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] produces ProblemDetails type for 401 status code.

May we know the status of this fix? Will it be released in v3.1 or in v5.0?

@icnocop
Copy link

icnocop commented Jan 17, 2021

I found a work-around here: domaindrivendev/Swashbuckle.AspNetCore#1752 (comment)

@mkArtakMSFT mkArtakMSFT changed the title ASP.NET Core 2.2 - ProducesResponseType(typeof(void), ...) causes ApiExplorer to indicate the return type is ProblemDetails ProducesResponseType(typeof(void), ...) causes ApiExplorer to indicate the return type is ProblemDetails Jan 26, 2021
@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, 6.0-preview2 Jan 26, 2021
@mkArtakMSFT mkArtakMSFT added the breaking-change This issue / pr will introduce a breaking change, when resolved / merged. label Jan 26, 2021
@ghost ghost added the Done This issue has been fixed label Mar 4, 2021
@ghost ghost removed the Working label Mar 4, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-medium This issue impacts approximately half of our customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates breaking-change This issue / pr will introduce a breaking change, when resolved / merged. bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed severity-major This label is used by an internal tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants