VelNaga
VelNaga

Reputation: 3953

Spring boot swagger configure global headers for an application

I am working on microservices using spring-boot-1.4.5. We are setting few headers in MDC while the interaction between microservices occurred. These headers are common across the microservices/application.There is an interceptor in each application which will check for this headers if it is not present the call will not reach controller. So for everything works fine. The problem is each application or services exposing a swagger-UI(swagger-ui:2.6.1).

I can able to see swagger-ui and all the endpoints in the application but i don't know how to show the global headers field under each endpoint.

How to customise swagger to show these global headers under each endpoint ? Any help or hint would be appreciable also i browsed google and saw other posts which are not useful or i couldn't grasp the things properly.

Upvotes: 1

Views: 3218

Answers (1)

Barath
Barath

Reputation: 5283

To set global parameters, use ParameterBuilder to build springfox.documentation.service.Parameter and set it to globalOperationParameters.

    @Bean
    public Docket api() {
        Parameter headerParam = new ParameterBuilder().name("TenantId").defaultValue("microservices").parameterType("header")
                .modelRef(new ModelRef("string")).description("Tenant Identity").required(true).build();

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .globalOperationParameters(Arrays.asList(headerParam))
          .select()                                  
          .apis(RequestHandlerSelectors.basePackage("com.app"))              
          .paths(PathSelectors.any())                          
          .build();

    }

Upvotes: 1

Related Questions