Not able to show HttpStatusCode.Created status code
See original GitHub issueI am not able to show status code & Example value if method return type is HttpStatusCode.Created on swagger ui. It’s working fine for return type HttpStatusCode.Ok. This is my controller and Example value class
In PersonController.cs
public class PersonController : ApiController
{
[HttpPost]
[Route("api/Person/save")]
[SwaggerResponseExample(HttpStatusCode.Created, typeof(PersonResponseExample))]
public HttpResponseMessage PostenericPerson(PersonRequest personRequest)
{
var result = 1;// "Created";
return Request.CreateResponse(HttpStatusCode.Created, result);
}
}
In PersonResponseExample.cs
internal class PersonResponseExample : IExamplesProvider
{
public object GetExamples()
{
return new PersonResponse
{
Id = 123,
Title = Title.Dr,
FirstName = "John",
LastName = "Doe",
Age = 27,
Income = null
};
}
}
This is the output i want to get i have mark in red.
Please let me know am i missing anything.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Unable to get a HttpStatusCode
I have written the following code on Visual Studio. I have been newly working on http protocols to study how they function.
Read more >What's the most appropiate http status code for 'not ...
In this case, it would return a 412 precondition failed. There's a case to be made for returning a 200, but a client's...
Read more >A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >HttpStatusCode Enum (System.Net)
Equivalent to HTTP status 405. MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource. MisdirectedRequest ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just did a quick google, and this will get rid of the unwanted 200 response, and now the example is displayed fine for the 201:
I had a look at your example. Your syntax is incorrect, it should be like this:
With that syntax, it IS working, as the Swagger document does contain the correct example for the 201 response:
However, the example is NOT showing up in swagger-ui. I forgot about that, but this is a Known issue and already documented in my project’s readme section under Known Issues.
Just so you know, the 201 example should be here: