生成的swagger.json中不包含XML内联注释

时间:2017-09-27 06:16:46

标签: c# swagger swashbuckle asp.net-core-2.0

生成的swagger.json文件不包含我已覆盖的方法的XML内联注释。对于所有其他方法,内联注释包含在生成的swagger.json中。 xml文件包含所有注释,以便该文件看起来是正确的。所有路线都正常运作。

为什么生成的swagger.json中包含所有XML注释?

    PetsApi.cs
    public abstract class PetsApiController : Controller
    { 

    /// <summary>
    /// Create a pet. 27th of Sept
    /// </summary>

    /// <response code="201">Null response</response>
    /// <response code="0">unexpected error</response>
    [HttpPost]
    [Route("/v1/pets")]
    [SwaggerOperation("CreatePets")]
    public virtual void CreatePets()
    { 
        throw new NotImplementedException();
    }


    /// <summary>
    /// List all pets. 27th of Sept
    /// </summary>

    /// <param name="limit">How many items to return at one time (max 100)</param>
    /// <response code="200">An paged array of pets</response>
    /// <response code="0">unexpected error</response>
    [HttpGet]
    [Route("/v1/pets")]
    [SwaggerOperation("ListPets")]
    [SwaggerResponse(200, type: typeof(Pets))]
    public virtual IActionResult ListPets([FromQuery]int? limit)
    { 
        string exampleJson = null;

然后我通过以下方式覆盖CreatePets:

    public class TestOfPets : Controllers.PetsApiController
{
    public override void CreatePets()
    {
        int testing;

Swagger UI中的结果将是这样的, Swagger UI

正如您所看到的,POST操作没有任何意见,为什么?

XML文件虽然包含了XML file

1 个答案:

答案 0 :(得分:0)

startUp.cs包含以下配置:

            var basePath = PlatformServices.Default.Application.ApplicationBasePath;
            var xmlPath = Path.Combine(basePath, "controllapi.xml");
            myData.IncludeXmlComments(xmlPath)

controllapi.xml不包含与TestOfPets相关的任何内容。它只包括PetsApiController.CreatePets。