Asp.Net core Swashbuckle set operationId

前端 未结 3 2065
梦谈多话
梦谈多话 2021-01-02 15:59

How can I set swagger operationId attribute in Asp.Net Core 2.1 project? According to this post I should use SwaggerOperationAttribute but I cannot

3条回答
  •  灰色年华
    2021-01-02 16:41

    You can enable annotation on swagger with the Swashbuckle.AspNetCore.Annotations nuget package. (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#swashbuckleaspnetcoreannotations)

    Once annotations have been enabled, you can enrich the generated Operation metadata by decorating actions with a SwaggerOperationAttribute.

    [HttpPost]
    
    [SwaggerOperation(
        Summary = "Creates a new product",
        Description = "Requires admin privileges",
        OperationId = "CreateProduct",
        Tags = new[] { "Purchase", "Products" }
    )]
    public IActionResult Create([FromBody]Product product)
    

提交回复
热议问题