Not supported by Swagger 2.0: Multiple operations with path

后端 未结 9 2272
盖世英雄少女心
盖世英雄少女心 2020-12-29 03:15

I have integrated swagger in WebApi 2 application. It works fine when application has single controller. When I added second controller in the application. I got following

9条回答
  •  轮回少年
    2020-12-29 03:24

    In the file AppStart/SwaggerConfig.cs

    First one, you must import Linq

    using System.Linq;
    

    And add in the same file, this line

    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
    

    just inside of:

    GlobalConfiguration.Configuration 
                    .EnableSwagger(c =>
                        { ...
    

    One consideration: In your controllers, you must use the Http methods :

    [HttpGet]
    [Route("something")]
    public List something(){....}
    
    [HttpGet]
    [Route("something2")]
    public List something2(){....}
    
    [HttpPost]
    [Route("mypost1")]
    public List mypost1(){....}
    
    [HttpPost]
    [Route("mypost2")]
    public List mypost2(){....}
    

提交回复
热议问题