Annotations on model properties in SwaggerUI

Viewed 608

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?

1 Answers

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.

Related