I can't seem to understand why my swagger doc UI is missing the Model Schema details for each Gets and Posts within my controller?
I am running SwashBuckle
for ASP.NET core nuget package v4.0.1 and even after upgrading to the latest package does nothing to show the schema details? (My WebAPI is build in Core 2.2)
I have ran through the swagger documentation only w.r.t configurations and nothing directs me to where I can get the additional information to be displayed?
After some research I found that if I use the following Attribute
[ProducesResponseType(typeof(Models.Customer), StatusCodes.Status200OK)]
[HttpGet("{Id}/customer")]
public async Task<IActionResult> GetCustomer(int Id)
Displays Schemas
block in the swagger UI which is exactly I want. However I don't want to go through
each of my Controller Get / Post methods and add this attribute. It always worked without this but what could be preventing this from working out of the box?
Swashbuckle creates the model based on the action's return type. You have several options:
You can return the actual type (e.g. public async Task<Models.Customer> GetCustomer(int Id)
If you return an IActionResult
, you can use the ProducesResponseType
attribute
You can return an ActionResult<T>
which works just like the IActionResult
but with the actual type
You can check the documentation for more information: https://learn.microsoft.com/en-us/aspnet/core/web-api/action-return-types?view=aspnetcore-3.1