NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

XML comments <remarks> not included in swagger.json for DTO properties

Open mabead opened this issue 4 years ago • 4 comments

I am using version 13.7.0 of NSwag.AspNetCore. With this, I have a DTO that is documented like this:

// In controller
[OpenApiOperation("GetMetadata")]
[ProducesResponseType(typeof(UserMetadataResponse), 200)]
public async Task<IActionResult> GetMetadata()
{
  // ...
}

public class UserMetadataResponse
{
    /// ...
	
    /// <summary>
    /// Indicates which version of each service offer that the user currently has access to.
    /// </summary>
    public ServiceOffersVersionDto ServiceOffersVersion { get; private set; }
}

public class ServiceOffersVersionDto
{
	/// <summary>
	/// The version of the 'FooBar' service offer.
	/// </summary>
	/// <remarks>
	/// The possible values are:
	/// * null: bla bla
	/// * -1: foo bar
	/// * 1: xyz
	/// </remarks>
	public int? FooBar { get; set; }
}

Then, when I start my ASP.Net service and look at the resulting swagger.json, I get this:

image

As you can see, my <summary> properly ends up in the generated swagger.json but my <remarks> are lost.

Is this a known limitation? Am I missing something for my <remarks> to end up in the swagger.json file?

mabead avatar Jan 20 '21 20:01 mabead

I think the reason is that OpenAPI/Swagger does not have a property where we could map this to. See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject

RicoSuter avatar Jan 20 '21 22:01 RicoSuter

Ok. @RicoSuter since the OpenAPI/swagger specification does not allow it, would it be an option for nswag to concatenate the <summary> and <remarks> text to fill the OpenAPI/swagger description property?

mabead avatar Jan 21 '21 11:01 mabead

You can do that with a custom operation processer and the Namotion.Reflection library (which is automatically available when referencing the NSwag library). Adding it out-of-the-box would be a "breaking change" and a too opinionated implementation.

RicoSuter avatar Jan 21 '21 19:01 RicoSuter

Hi, could you please outline how to do this? I think that having the XML comments from the controller available in the generated client code too.

Peter-Svahn avatar Jul 08 '22 10:07 Peter-Svahn