Spring + Springfox + Header参数 [英] Spring + Springfox + Header Parameters
问题描述
@RequestMapping(...)
public Foo getFoo(@HeaderParam("header") final String header) {
...
}
像上面那样添加一个@HeaderParam
方法参数springfox进行选择,当我查看swagger-ui时,它具有一个用于标题的字段.这正是我想要的.有没有一种方法可以告诉springfox在一组方法中包含此标头参数,而不必在方法本身中包含这些参数?我们真正要做的是一个使用标头的servlet过滤器,我们希望可以通过swagger-ui轻松设置它.
Adding a @HeaderParam
method parameter as above springfox picks it up and when I look at the swagger-ui it has a field for the header. This is exactly what I want. Is there a way I can tell springfox to include this header parameter on a set of methods without having to include the parameters on the method itself? What we really have going on is a servlet filter which uses the header and we'd like an easy to set it through the swagger-ui.
推荐答案
您可以在案卷定义中使用globalOperationParameters
.例如
You could use the globalOperationParameters
in the docket definition. For e.g.
new Docket(...)
.globalOperationParameters(
Arrays.asList(new ParameterBuilder()
.name("header")
.description("Description of header")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(true)
.build()))
请参见#22 以获得更多信息.
See #22 in the documentation for more information.
这篇关于Spring + Springfox + Header参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!