Skip to content

OpenAPI: OpenApiSecuritySchemeReference is not resolved #64524

@vchirikov

Description

@vchirikov

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

@captainsafia

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions