Skip to content
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

Void with ResponseType attribute #344

Closed
henkosch opened this issue May 20, 2015 · 5 comments
Closed

Void with ResponseType attribute #344

henkosch opened this issue May 20, 2015 · 5 comments
Milestone

Comments

@henkosch
Copy link

Take a look at the following snippet:

public class ValuesController : ApiController
{
    public void Put()
    {
    }

    [ResponseType(typeof(void))]
    public IHttpActionResult Post()
    {
        return StatusCode(HttpStatusCode.NoContent);
    }
}

I expect the two operation to have the same result in the responses field.

Both should have:

"responses":{"204":{"description":"No Content"}}

But instead the Post operation gets the following:

"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Void"}}}

This generates the following on swagger-ui:
screenshot 2015-05-21 00 50 56

Which is clearly wrong. I need the Post operation to have IHttpActionResult, so I can return with BadRequest() or Unauthorized() etc. That is why I used the ResponseType attribute to specify when it succeeds it should return 204 No content, without a schema reference.

How can I remove these strange "schema":{"$ref":"#/definitions/Void"} references from my operations?

@domaindrivendev
Copy link
Owner

This is a SB bug - just isnt handled because I never thought of the case where you would use ResponseType instead of void on the action signature. Simple fix ... will go out with next release

@domaindrivendev
Copy link
Owner

In the meantime, you could do the following as a workaround ...

[SwaggerResponseRemoveDefaults]
[SwaggerResponse(204, "No Content")]
public IHttpActionResult Post()
{
    ...
}

@domaindrivendev
Copy link
Owner

Should be resolved in latest release - 5.2.0

@dmyers
Copy link

dmyers commented Jun 4, 2015

Thanks I needed this too! Great release! 👍

@mc0re
Copy link

mc0re commented Mar 14, 2019

What about .NET Core version? It has no SwaggerResponseRemoveDefaults attribute, and [ProducesResponseType(StatusCodes.Status204NoContent, Type = typeof(void))] does not seem to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants