I am trying to add custom request header to every API I can do it by adding a piece of code to every API
`public ResponseDTO setNames(@RequestHeader(value="my-header",required = false HttpServletRequest httpServletRequest) throws Exception {}`
But I want this to be done automatically like we have authorisation header by default when we create a new API.How can this be done can anyone tell me a good solution
enter image description here
Adding a java version of the Kotlin answer
@Bean
GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("add-user-id-header")
.addOperationCustomizer((operation, $) -> {
operation.addParametersItem(
new HeaderParameter()
.name("Authorization")
.description("Access Token")
.required(true)
);
return operation;
})
.build();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With