{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/4863","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/4863/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/4863/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/4863/events","html_url":"https://github.com/aspnet/Mvc/issues/4863","id":160231084,"number":4863,"title":"How to indicate API respones, that don't return a body, with ProducesResponseTypes","user":{"login":"domaindrivendev","id":1434343,"avatar_url":"https://avatars.githubusercontent.com/u/1434343?v=3","gravatar_id":"","url":"https://api.github.com/users/domaindrivendev","html_url":"https://github.com/domaindrivendev","followers_url":"https://api.github.com/users/domaindrivendev/followers","following_url":"https://api.github.com/users/domaindrivendev/following{/other_user}","gists_url":"https://api.github.com/users/domaindrivendev/gists{/gist_id}","starred_url":"https://api.github.com/users/domaindrivendev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domaindrivendev/subscriptions","organizations_url":"https://api.github.com/users/domaindrivendev/orgs","repos_url":"https://api.github.com/users/domaindrivendev/repos","events_url":"https://api.github.com/users/domaindrivendev/events{/privacy}","received_events_url":"https://api.github.com/users/domaindrivendev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-06-14T16:52:56Z","updated_at":"2016-07-26T15:10:45Z","closed_at":null,"body":"Is there a convenient way to indicate additional HTTP status codes for an API action, without specifying a response type? For example, with a 404 response, it's extremely common to return no content in the response body. It looks like the following syntax is required for this:\r\n\r\n    [ProducesResponseType(typeof(Cart), 200)]\r\n    [ProducesResponseType(typeof(void), 404)]\r\n    [HttpGet(\"/carts/{id}\")]\r\n    public IActionResult GetById(int id)\r\n    {\r\n        ....\r\n    }\r\n\r\nThis is probably fine but gives me a \"niggly\" feeling that the semantics for ProducesResponseType don't quite align with typical API design. In HTTP, there's ALWAYS a status code and OPTIONALLY a response body. IMO, this reality would be better reflected by renaming the attribute to \"ProducesResponse\" (or even just \"Produces\") with an optional Type parameter:\r\n\r\n    [ProducesResponse(200, typeof(Cart))]\r\n    [ProducesResponse(404)]\r\n    [HttpGet(\"/carts/{id}\")]\r\n    public Cart GetById(int id)\r\n    {\r\n        ....\r\n    }\r\n\r\nPerhaps I'm missing something so would be great to hear other's opinions. It's not the end of the world either way but just wanted to put forward my two cents.\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/235298921","html_url":"https://github.com/aspnet/Mvc/issues/4863#issuecomment-235298921","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/4863","id":235298921,"user":{"login":"clydin","id":19598772,"avatar_url":"https://avatars.githubusercontent.com/u/19598772?v=3","gravatar_id":"","url":"https://api.github.com/users/clydin","html_url":"https://github.com/clydin","followers_url":"https://api.github.com/users/clydin/followers","following_url":"https://api.github.com/users/clydin/following{/other_user}","gists_url":"https://api.github.com/users/clydin/gists{/gist_id}","starred_url":"https://api.github.com/users/clydin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clydin/subscriptions","organizations_url":"https://api.github.com/users/clydin/orgs","repos_url":"https://api.github.com/users/clydin/repos","events_url":"https://api.github.com/users/clydin/events{/privacy}","received_events_url":"https://api.github.com/users/clydin/received_events","type":"User","site_admin":false},"created_at":"2016-07-26T15:10:45Z","updated_at":"2016-07-26T15:10:45Z","body":"I ran into the same issue.\r\nWith the status code first, I've also found the code is easier to read due to the status code having a consistent length of 3 characters; whereas the type varies.\r\n\r\nI've been adding the following into each of my new projects:\r\n\r\n```\r\npublic class ProducesResponseAttribute : ProducesResponseTypeAttribute\r\n{\r\n        public ProducesResponseAttribute(int statusCode, Type type = null)  \r\n            : base(type ?? typeof(void), statusCode)  \r\n        { }  \r\n}  \r\n```"}}
{"actor":{"display_login":"clydin"}}