asp.net-coreswaggeropenapi

NSwag - how do I add comments?


I use NSwag in an ASP.Net WebAPI project to generate a swagger interface - which works great.

Say I have a method I want to add some explanations to - how can I do that?

By comment I mean something that when a user of the API is looking at the documentation will see.

I have googled, binged and ... ducked? - but was unable to find anything about it. Maybe I am using wrong terms.


Solution

  • To use annotation-based documentation with NSwag you must install the package NSwag.Annotations.

    Then you can use annotations like that:

    [SwaggerResponse(HttpStatusCode.OK, typeof(MyResponseType), Description = "Returns the object containing data ...")]
    

    There are many annotations to choose from; each are presented differently in the web UI.