Swashbuckle set manually operationId, multiple operations with same verb

前端 未结 2 1486
北荒
北荒 2020-11-30 09:56

I need to know if it\'s possible to set up custom operationid, or a naming convention, I mean I know that operation filter can be overwritten the way how operationId is gene

相关标签:
2条回答
  • 2020-11-30 10:25

    For swashbuckle 5.0, you can use the Name attribute. You can set it to any string but I'm a fan of using nameof like this: nameof(ActualMethodName).

    [HttpGet("{id:int}", Name = nameof(GetProductById))]
    public IActionResult GetProductById(int id) // operationId = "GetProductById"'
    

    or

    [HttpGet("{id:int}", Name = "GetProductById")]
    public IActionResult GetProductById(int id) // operationId = "GetProductById"'
    

    There are a few other options listed here

    0 讨论(0)
  • 2020-11-30 10:37

    EDIT This answer relates to Swashbuckle 5.6 and .NET Framework. Please read mwilson's answer for Swashbuckle and .NET Core

    You can use the SwaggerOperationAttribute provided by Swashbuckle for that.

    [SwaggerOperation("get")]
    public IEnumerable<Contact> Get()
    {
        ....
    }
    
    [SwaggerOperation("getById")]
    public IEnumerable<Contact> Get(string id)
    {
        ...
    }
    

    You can use that attribute to add tags and schemes to your operation as well by the way. Have a look at the source code

    0 讨论(0)
提交回复
热议问题