-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
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
Microsoft.AspNetCore.OpenApi 10.0.0 / Microsoft.OpenApi 2.3.10
I have document transformer:
opt.AddDocumentTransformer((document, _, _) => {
document.Components ??= new OpenApiComponents();
document.Components.SecuritySchemes ??=
new Dictionary<string, IOpenApiSecurityScheme>(StringComparer.Ordinal);
document.Components.SecuritySchemes.TryAdd("bearer", new OpenApiSecurityScheme {
Name = "Authorization",
Description = "Put here **ONLY** Json Web Token",
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
});
return Task.CompletedTask;
});
which correctly adds the security schema in schema json:
"securitySchemes": {
"bearer": {
"type": "http",
"description": "Put here **ONLY** Json Web Token",
"scheme": "bearer",
"bearerFormat": "JWT"
},
// ...But I can't use the OpenApiSecuritySchemeReference to it (it's unresolved):
e.g.
opt.AddOperationTransformer((operation, context, _) => {
if (context.Description.ActionDescriptor.EndpointMetadata.OfType<IAuthorizeData>().Any()) {
operation.Security ??= new List<OpenApiSecurityRequirement>();
operation.Security.Add(new OpenApiSecurityRequirement() {
{ new OpenApiSecuritySchemeReference("bearer"), [] },
});
}
});result json:
"security": [
{ }
]I also tried add securityschema in operation transformer (which is earlier in pipeline) with no success, the OpenApiSecuritySchemeReference is always unresolved. IDK maybe the bug inside https://github.com/microsoft/OpenAPI.NET
petrzjunior
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