javaswaggerswagger-codegen

How to define Swagger SecurityScheme in a Spring Boot Application


I'm trying to define a http basic auth requirement as a default for my application:

components:
 securitySchemes:
   BasicAuth:
    type: http
    scheme: basic

But my BasicAuth security class isn't being generated in the swagger.json file.

I've defined a class with the @SecurityScheme annotation with io.swagger.v3.oas.annotations.security.

@SecurityScheme(type = SecuritySchemeType.HTTP, name = "basic")
public class BasicAuth {
}

In my OpenApi definition I've added the SecuirtyRequriment:

SecurityRequirement requirement = new SecurityRequirement();
requirement.addList("BasicAuth");

Solution

  • So I figured what I was doing wrong, I had to annotate at least one Resource with the basic security scheme. After that it showed up on the Swagger.json file