1

I have a microservice-A which gets the token as a header from another microservice-B. Now I want to implement swagger2 in microservice-A. The problem is every request flows through microservice-B. So swagger-ui throws error in local as

it is not able to get those header parameter which microservice-B is trying to fetch.

Ubercool
  • 1,029
  • 2
  • 14
  • 29
Pooja Mahapatra
  • 105
  • 3
  • 11

1 Answers1

0

It is not able to get those header parameter which microservice-B is trying to fetch.

Swagger on its own can't call the authenticator service and add the obtained token to another request's header.

You can modify the Docket object to accept additional parameter in header as below:

docket.globalOperationParameters(
    Collections.singletonList(new ParameterBuilder()
      .name("Authorization")
      .description("Bearer [token]")
      .modelRef(new ModelRef("string"))
      .parameterType("string")
      .required(true)
      .build()
    )
);

This will allow Swagger UI to show additional field to accept token (see image below). You need to obtain the token by yourself and can put in this field.

enter image description hereHope this helps.

Ubercool
  • 1,029
  • 2
  • 14
  • 29
  • The issue is...every request flows through one of the microservice, then gets redirected to another microservice, even the swagger hits the microservice first and fails as there is no token in the header. So the UI doesn't generate, it gives error. – Pooja Mahapatra Apr 04 '18 at 05:41
  • Can't help more without looking at code or error stack – Ubercool Apr 04 '18 at 06:35