java 在 swagger UI 试用中发送动态自定义标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26742521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending dynamic custom headers in swagger UI try outs
提问by Sharath B. Patel
I am using swagger in java.
我在 Java 中使用 swagger。
I am reading a header called callerId through requestAttributes in the code. I am not using the header through the annotation @HeaderParam.
我正在通过代码中的 requestAttributes 读取一个名为 callerId 的标头。我没有通过注释@HeaderParam 使用标题。
because of this reason, the header section is not showing up in the swagger UI for try outs.
由于这个原因,标题部分没有显示在 swagger UI 中以供试用。
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.
提前致谢。
回答by Ron
You can add parameters to an operation using @ApiImplicitParams and @ApiImplicitParam.
您可以使用@ApiImplicitParams 和@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
以下 wiki 文档应为您提供有关如何使用这些注释的说明 - 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.
请记住,我在这里假设这不是安全标头,而是 API 的实际组成部分(至少基于您提供的描述)。如果您正在寻找安全标头,还有另一种方法。请发表评论,我将编辑此回复。