【问题标题】:XML inline comments are not included in the generated swagger.json生成的 swagger.json 中不包含 XML 内联注释
【发布时间】:2017-09-27 06:16:46
【问题描述】:

生成的 swagger.json 文件不包含我已覆盖的方法的 XML 内联 cmets。对于所有其他方法,内联 cmets 包含在生成的 swagger.json 中。 xml 文件包含所有 cmets,因此该文件似乎是正确的。所有路线都在正常工作。

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

    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 操作没有任何 cmets,为什么?

XML 文件包含它们,XML file

【问题讨论】:

  • 从 StartUp.cs 发布您的 Swagger 配置。您必须实际告诉 Swagger 使用 XML 文件,而您可能没有这样做。
  • 你案例中的 cmets 来自 TestOfPets.CreatePets 不是来自父级,检查生成的 XML 文件确认

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


【解决方案1】:

startUp.cs 包含以下配置:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-01
    • 2010-10-15
    • 1970-01-01
    • 2012-01-24
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    相关资源
    最近更新 更多