Unable to set global parameters
Describe the bug
I want to set a global parameter, but it seems that it doesn't work well
The official document is as follows
But this option is not available in my API
I tried to set it in Components similar to the Security Scheme, but it didn't take effect
How should I set up my global header?
I used Spring Security, and the login address of Spring Security is implicit and cannot be displayed in Apidoc. How can I add the login API to Apidoc?
I have same issue. Below is my sample codes, but it does not take effect, which means I can't see the configured headers on swagger-ui.
@Bean
fun openAPI(): OpenAPI {
return OpenAPI()
.components(
Components()
.addHeaders(
"myHeader2",
Header().description("myHeader2 header").schema(StringSchema())
)
)
.info(
Info().title("Test API").version("0.0.1")
.description("Test api!!!")
.termsOfService("http://swagger.io/terms/")
)
}
@zhangpan-soft could you try below codes? it looks working. But I am not sure why the way you used does not work.
@Bean
fun globalOpenApiCustomizer(): GlobalOpenApiCustomizer {
val customHeaderParameter = Parameter()
customHeaderParameter.`in`("header").name("custom header")
return GlobalOpenApiCustomizer { openApi ->
openApi.paths.values.forEach { pathItem ->
pathItem.readOperations().forEach { op ->
op.addParametersItem(customHeaderParameter)
}
}
}
}
The above code works for me. Thank you, @ryukato.
In case someone needs the Java version:
@Bean
public GlobalOpenApiCustomizer globalOpenApiCustomizer() {
Parameter customHeaderParameter = new Parameter().in("header").name("custom header");
return openApi -> {
openApi.getPaths().values().forEach(pathItem -> {
pathItem.readOperations().forEach(op -> {
op.addParametersItem(customHeaderParameter);
});
});
};
}