Chris Peng
Chris Peng

Reputation: 946

springfox-swagger-ui: How to exclude routes from global parameter

Say I created a global parameter token for all my APIs:

    List<Parameter> commonParameters = new ArrayList<>();
    commonParameters.add(new ParameterBuilder()
        .name("token")
        .description("Token for api access")
        .modelRef(new ModelRef("string"))
        .parameterType("header")
        .required(true)
        .build());
    return new Docket(DocumentationType.SWAGGER_2)
        .globalOperationParameters(commonParameters)
       // rest ignored .....

This token is required for almost every API, except one that can be publicly accessed. How do I exclude this one API from the global operation parameter?

Upvotes: 1

Views: 2404

Answers (2)

Michał Stochmal
Michał Stochmal

Reputation: 6630

The only workaround I found is to override globally defined header by using @ApiImplicitParams annotation.

So in your case:

@ApiImplicitParams({
        //Overriding global behavior.
        @ApiImplicitParam(
                name = "token")
})

Unfortunately, header will be still visible on swagger, but parameter won't be marked as required.

Upvotes: 0

Madhu Bhat
Madhu Bhat

Reputation: 15193

Currently exclusion for globalOperationParameters is not provided and there's an open feature request for the same in this GitHub issue.

Upvotes: 2

Related Questions