I have a Swagger config like this
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
List
For a quick solution, I configured my docket with a global parameter authorization header in my swaggerConfig class.
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private static final Set DEFAULT_PRODUCES_CONSUMES = new HashSet(Arrays.asList("application/json"));
@Bean
public Docket api() {
ParameterBuilder parameterBuilder = new ParameterBuilder();
parameterBuilder.name("Authorization")
.modelRef(new ModelRef("string"))
.parameterType("header")
.description("JWT token")
.required(true)
.build();
List parameters = new ArrayList<>();
parameters.add(parameterBuilder.build());
return new Docket(DocumentationType.SWAGGER_2).apiInfo(DEFAULT_API_INFO)
.produces(DEFAULT_PRODUCES_CONSUMES)
.consumes(DEFAULT_PRODUCES_CONSUMES)
.select()
.build()
// Setting globalOperationParameters ensures that authentication header is applied to all APIs
.globalOperationParameters(parameters);
}
}
Wrote a small post authorization-field-in-swagger-ui about this.