Swagger使用--在一个Controller中使用相同(类似)参数的方法

解决方法:在Startup.cs中加入CustomSchemaIds

 // Register the Swagger generator, defining 1 or more Swagger documents
 services.AddSwaggerGen(c =>
{
        c.SwaggerDoc("v1", new Info { Title = "CompareAPI", Version = "v1" });
        c.CustomSchemaIds((type) => type.FullName);//根据全名来生成
});

控制器代码类似:

    [Route("api/[controller]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        [HttpPost]
        [Route("Register")]
        public async Task<ActionResult<T>> Register(RegisterModel registerModel)
        {
        }
        [HttpPost]
        [Route("ResetPassword")]
        public async Task<ActionResult<T>> ResetPassword(ResetPasswordModel resetPasswordModel)
        {
        }
    }

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#customize-schema-ids

posted @ 2019-06-29 21:40  TTonlyV5  阅读(1415)  评论(0编辑  收藏  举报