Greg Graham
Greg Graham

Reputation: 474

Annotations on model properties in SwaggerUI

I have built a ASP.Net Core 3.1 Web API, and I am interested in auto-generating documentation for my clients. I've followed the very simple instructions found here: Microsoft docs to install either NSwag or Swashbuckle in my project and in both cases I can see documentation for my APIs, but there are no descriptions on the model properties.

Java seems to have an @ApiModelProperty annotation for this, but I don't see a similar attribute in .Net. Is it possible to add descriptions for Model properties in either of these swagger implementations, that would show up in Schema section in the Swagger UI?

Upvotes: 2

Views: 2194

Answers (1)

bmiller
bmiller

Reputation: 1783

Standard xml doc summary works for me.

public class TokenRefreshRequest
{
    /// <summary>
    /// The JWT access token
    /// </summary>
    public string AccessToken { get; set; }

    /// <summary>
    /// The refresh token that was sent via the new token endpoint or the last refresh.
    /// </summary>
    public string RefreshToken { get; set; }
}

Shows on the swagger page as;

enter image description here

You can add limited markdown as well but I can't seem to find the link.

Upvotes: 1

Related Questions