Mugdha
Mugdha

Reputation: 181

Default value for accept header using springdoc-openapi

I'm using springdoc-openapi library for auto generation and rendering of swagger-ui. I need to add default value for accept header. How to do this?

springfox allows to do this using defaultValue function of ParameterBuilder. Attaching the screenshot. I want to achieve the same without using springfox.

enter image description here

Upvotes: 0

Views: 3248

Answers (1)

user11878890
user11878890

Reputation:

If you need to add global parameter in the Header to all your operations, you can use OperationCustomizer :

@Bean
public OperationCustomizer addCustomGlobalHeader() {
    return (Operation operation, HandlerMethod handlerMethod) -> {
        Parameter headerParameter = new Parameter().in(ParameterIn.HEADER.toString()).required(true).
                schema(new StringSchema().
                        _default("application/json;api-verision=1.0")).name("Accept");
        operation.addParametersItem(headerParameter);
        return operation;
    };
}

Upvotes: 3

Related Questions