Java swagger core 2.0禁用端点的安全性

Java swagger core 2.0禁用端点的安全性,java,openapi,Java,Openapi,我正在使用Swagger Core 2.0生成openAPI 3.0定义文件和 我无法禁用特定端点的“安全性”。 我已定义securitySchemes和根安全元素: { "openapi" : "3.0.1", "security" : [ { "JWT" : [ ] } ], "paths" : { "/auth" : { "post" : { "summary" : "authenticate user",

我正在使用Swagger Core 2.0生成openAPI 3.0定义文件和
我无法禁用特定端点的“安全性”。 我已定义securitySchemes和根安全元素:

{
  "openapi" : "3.0.1",
  "security" : [ {
    "JWT" : [ ]
  } ],
  "paths" : {   
    "/auth" : {
      "post" : {
        "summary" : "authenticate user",
        "operationId" : "authenticate",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/AuthenticationRequest"
              }
            }
          }
        },
        "responses" : {
          "200" : {
            "description" : "when user is successfully authenticated",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/AuthenticateUserOutput"
                }
              }
            }
          },       
          "401" : {
            "description" : "when email/password not valid or user is blocked/inactive"
          }       
        }
      }
    },
  },
  "components" : {
    "schemas" : {
      "AuthenticateUserOutput" : {
        "type" : "object",
        "properties" : {
          "token" : {
            "type" : "string"
          },
          "lastLoginAt" : {
            "type" : "string",
            "format" : "date-time"
          },        
          "lastProjectId" : {
            "type" : "string"
          }
        }
      },
      ...,
      "AuthenticationRequest" : {
        "required" : [ "email", "password" ],
        "type" : "object",
        "properties" : {
          "email" : {
            "type" : "string"
          },
          "password" : {
            "type" : "string"
          }
        }
      }
    },
    "securitySchemes" : {
      "JWT" : {
        "type" : "http",
        "scheme" : "bearer",
        "bearerFormat" : "JWT"
      }
    }
  }
}
根据开放式API 3规范https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#securityRequirementObject 我将能够覆盖单个操作的全局“安全要求”。我想“禁用”一些操作的JWT安全性,并根据https://github.com/OAI/OpenAPI-Specification/blob/3.0.1/versions/3.0.1.md#securityRequirementObject 可以这样做:

要删除顶级安全声明,可以使用空数组

不幸的是,我正在努力使用注释在操作级别定义“空安全阵列”。。。 我试图具体说明

security = {}

但操作中根本没有生成任何安全元素。。。。 有什么想法吗

下面是我的java代码(我用于swagger dropwizard集成),它允许定义SecurityScheme和根级别的安全性

 Info info = new Info()
            .title("someTitle")
            .description("some description")
            .version("1.0")

    SecurityScheme jwtSecurity = new SecurityScheme()
            .type(SecurityScheme.Type.HTTP)
            .name("Authorization")
            .in(SecurityScheme.In.HEADER)
            .scheme("bearer")
            .bearerFormat("JWT");

    String securitySchemaName = "JWT";
    OpenAPI oas = new OpenAPI()
            .info(info)
            .components(new Components().addSecuritySchemes(securitySchemaName, jwtSecurity))
            .addSecurityItem(new SecurityRequirement().addList(securitySchemaName));

    SwaggerConfiguration oasConfig = new SwaggerConfiguration()
            .openAPI(oas)
            .prettyPrint(true)
            .resourcePackages(Stream.of("my.resources.package")
                    .collect(Collectors.toSet()));
    environment.jersey().register(new OpenApiResource()
            .openApiConfiguration(oasConfig));
然后在几个专用端点上,我想禁用安全性,因此我尝试使用:

    @POST
@Operation(
        summary = "authenticate user",
        responses = {
                @ApiResponse(responseCode = "200", description = "when user is successfully authenticated",
                        content = @Content(schema = @Schema(implementation = AuthenticateUserOutput.class))),                   
                @ApiResponse(responseCode = "401", description = "when email/password not valid or user is blocked/inactive"),
        }
        ,security = what to put here ?
)

根据对该项目的评论。这应该是可能的

你试过这个吗

security: [
  {}
]

我在JavaSpringBootWebApp(dependency org.springdoc:springdocOpenAPI ui:1.5.2)上也遇到了同样的问题。根据,我在操作上添加了一个空的
@SecurityRequirements
注释,解决了这个问题。例如:

@POST
@安全要求
@操作(
summary=“验证用户”,
答复={
@ApiResponse(responseCode=“200”,description=“当用户成功通过身份验证时”,
content=@content(schema=@schema(implementation=AuthenticateUserOutput.class)),
@ApiResponse(responseCode=“401”,description=“当电子邮件/密码无效或用户被阻止/不活动时”),
} )
)

您可以发布带有注释的Java代码吗?我刚刚编辑了一篇文章,添加了全局配置和特定于端点的配置。您找到解决方案了吗?它现在让我头疼
security: [
  {}
]