Sending dynamic custom headers in swagger UI try o

2019-03-26 08:44发布

问题:

I am using swagger in java.

I am reading a header called callerId through requestAttributes in the code. I am not using the header through the annotation @HeaderParam.

because of this reason, the header section is not showing up in the swagger UI for try outs.

How can I make this header show up in the try out form.

Is there any way I can achieve this without hard coding the header value.

Thanks in advance.

回答1:

You can add parameters to an operation using @ApiImplicitParams and @ApiImplicitParam.

The following wiki documentation should provide you with an explanation on how to use these annotations - https://github.com/swagger-api/swagger-core/wiki/Annotations#apiimplicitparam-apiimplicitparams

Keep in mind I assume here that this is not a security header but actually part of the API (at least based on the description you gave). If you're looking for a security header, there's an alternative method. Please leave a comment and I'll edit this response.