在 swagger UI 试用中发送动态自定义标头自定义、动态、swagger、UI

2023-09-07 14:19:38 作者:勞資早看透妳的心肝脾肺了

我在 java 中使用 swagger.

I am using swagger in java.

我正在通过代码中的 requestAttributes 读取一个名为 callerId 的标头.我没有通过注解@HeaderParam 使用标题.

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

由于这个原因,标题部分没有显示在招摇 UI 中以供试用.

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.

提前致谢.

推荐答案

您可以使用@ApiImplicitParams 和@ApiImplicitParam 向操作添加参数.

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

以下 wiki 文档应为您提供有关如何使用这些注释的说明 - https://github.com/swagger-api/swagger-core/wiki/Annotations#apiimplicitparam-apiimplicitparams

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

请记住,我在这里假设这不是安全标头,而是实际上是 API 的一部分(至少基于您提供的描述).如果您正在寻找安全标头,还有另一种方法.请发表评论,我将编辑此回复.

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.

 
精彩推荐
图片推荐