Skip to content
Advertisement

How to handle header field with swagger in a java project?

I want to add header parameters to swagger ui so that the user can pass these values also.
Could someone guide on what the java code for this would look like. I am using springfox-swagger2 and springfox-swagger-ui version 2.9.x

(There are other post of SOF that describe about adding these through swagger editor or are for other technologies, so they did not help.)
And google search did not help either. So relying on SOF for a solution.

Answer

You need to add the @ApiParam on the header field, like the following:

@ApiParam(value = "auth token")
@RequestHeader(value = "Authorization", required = false) String authToken

And it will be available on swagger.

Advertisement