我已经设置了两个Swagger文档版本/描述:
builder.Services.AddSwaggerGen(setupAction =>
{
setupAction.SwaggerGeneratorOptions.SwaggerDocs.Add("v1", new OpenApiInfo()
{
Version = "v1",
Title = "MY API version 1",
Description = "This is my API in version1",
});
setupAction.SwaggerGeneratorOptions.SwaggerDocs.Add("v2", new OpenApiInfo()
{
Version = "v2",
Title = "MY API version 2",
Description = "This is my API in version2",
});
我可以在以下位置看到生成的文档:
请输入您的密码
{
"openapi": "3.0.1",
"info": {
"title": "MY API version 1",
"description": "This is my API in version1",
"version": "v1"
},
"paths": {
您的位置:首页〉〉
{
"openapi": "3.0.1",
"info": {
"title": "MY API version 2",
"description": "This is my API in version2",
"version": "v2"
},
"paths": {
但是,我无法找到SwaggerUI从版本v2开始时如何设置默认版本,以及为什么“选择定义”下拉菜单中只有版本v1可用:
1条答案
按热度按时间tmb3ates1#
这里有一个完整的工作演示,如果有任何遗漏,您可以遵循:
1.配置
SwaggerOptions
以注册所有API版本:2.Program.cs:
注意:请务必安装
Microsoft.AspNetCore.Mvc.Versioning
和Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer
。3.Controller:
4.Result: