-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
In the previous version of Microsoft.OpenAPI we had the following
public OpenApiSecurityScheme(OpenApiSecurityScheme securityScheme)
{
Type = securityScheme?. Type ?? Type;
Description = securityScheme?. Description ?? Description;
Name = securityScheme?. Name ?? Name;
In = securityScheme?. In ?? In;
Scheme = securityScheme?. Scheme ?? Scheme;
BearerFormat = securityScheme?. BearerFormat ?? BearerFormat;
Flows = securityScheme?. Flows != null ? new(securityScheme?. Flows) : null;
OpenIdConnectUrl = securityScheme?. OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString, UriKind.RelativeOrAbsolute) : null;
Extensions = securityScheme?. Extensions != null ? new Dictionary<string, IOpenApiExtension>(securityScheme.Extensions) : null;
UnresolvedReference = securityScheme?. UnresolvedReference ?? UnresolvedReference;
Reference = securityScheme?. Reference != null ? new(securityScheme?. Reference) : null;
}
But they remove the reference in version 2.0.0.0 and also i believe there are some breaking changes since if i use .NET 10 preview 2 to add securityrequirement it does not work at all
Previously what works in .NET 9 is below
builder. Services.AddSwaggerGen(options =>
{
options. AddSecurityDefinition("JwtBearerDefaults.oa", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme. \r\n\r\n " +
"Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\n" +
"Example: \"Bearer 12345abcdef\"",
Name = "Authorization",
In = ParameterLocation.Header,
Scheme = JwtBearerDefaults.AuthenticationScheme,
});
options. AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
},
In = ParameterLocation.Header,
},
new List<string>()
}
});
});
but if i add it exactly in program.cs after adding the swashbuckle nuget package it does not work in .NET 10 Preview 2 Web API
Is there a workaround for this?
Expected Behavior
it should work as expected like in .NET 9
Steps To Reproduce
create a new .net 10 preview 2 web api project.
add swashbuckle nuget package
add the following in program.cs
builder. Services.AddSwaggerGen(options =>
{
options. AddSecurityDefinition("JwtBearerDefaults.oa", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme. \r\n\r\n " +
"Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\n" +
"Example: \"Bearer 12345abcdef\"",
Name = "Authorization",
In = ParameterLocation.Header,
Scheme = JwtBearerDefaults.AuthenticationScheme,
});
options. AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
},
In = ParameterLocation.Header,
},
new List<string>()
}
});
});
Exceptions (if any)
No response
.NET Version
.NET 10 preview 2
Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi