-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
I have 2 versions of my API so I'm using the following code to generate 2 swagger docs, one per version:
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "API v1",
Version = "v1",
Description = "API v1"
});
c.SwaggerDoc("v2", new OpenApiInfo
{
Title = "API v2",
Version = "v2",
Description = "API v2"
});This works as expected and generates 2 different swagger docs, and Swagger UI correctly shows the different docs. When publishing the application, I need to add the server and authentication settings to the generated docs. I am using this code to add the server
c.AddServer(new OpenApiServer
{
Url = server
});and this code to add auth:
c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
In = ParameterLocation.Header,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = Configuration.GetValue<Uri>(authUri),
Scopes = new Dictionary<string, string> { { "user_impersonation", "Access API" } }
}
}
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "oauth2"
},
Scheme = "oauth2",
Name = "oauth2",
In = ParameterLocation.Header
}, Array.Empty<string>()
}});This produces the expected v1 doc with the server and auth scheme:
However the v2 doc does not have the server or auth URL.
Is this perhaps a bug, or is there additional config code I needed when generating multiple swagger docs for versioning?
Expected behavior
The current code should produce 2 docs with identical server and authentication info since the AddServer() function doesn't allow targeting a specific doc.
Swashbuckle.AspNetCore version
7.3.1
.NET Version
net8.0

