Describe the bug
Following the steps in the FAQ and here to add a global header. The header isn't added to every endpoint.
To Reproduce
Enter the following somewhere Spring Boot will pick it up:
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("spring_oauth", new SecurityScheme()
.type(SecurityScheme.Type.OAUTH2)
.description("Oauth2 flow")
.flows(new OAuthFlows()
.authorizationCode(new OAuthFlow()
.authorizationUrl(authUrl + "/auth")
.refreshUrl(authUrl + "/token")
.tokenUrl(authUrl + "/token")
.scopes(new Scopes())
)))
.addSecuritySchemes("api_key", new SecurityScheme()
.type(SecurityScheme.Type.APIKEY)
.description("Api Key access")
.in(SecurityScheme.In.HEADER)
.name("API-KEY")
)
.addHeaders("Version", new Header()
.description("version header")
.required(true)
.schema(new StringSchema())))
.security(Arrays.asList(
new SecurityRequirement().addList("spring_oauth"),
new SecurityRequirement().addList("api_key")));
}
Expected behavior
Header Version should appear in the Swagger UI under every endpoint, but it does not.
Additional context
I could be misunderstanding the FAQ, if so I apologize.
Hi @keith-miller,
Your first part of configuration is correct.
If you want your Header Version to appear in the Swagger UI under every endpoint, you still need to add:
@Bean
public OpenApiCustomiser customerGlobalHeaderOpenApiCustomiser() {
return openApi -> openApi.getPaths().values().stream().flatMap(pathItem -> pathItem.readOperations().stream())
.forEach(operation -> operation.addParametersItem(new HeaderParameter().$ref("#/components/headers/Version")));
}
You have also a sample Test here:
Thanks!
Most helpful comment
Hi @keith-miller,
Your first part of configuration is correct.
If you want your Header Version to appear in the Swagger UI under every endpoint, you still need to add:
You have also a sample Test here: