gpt4 book ai didi

java - Swagger UI 不显示所有 header 值

转载 作者:太空宇宙 更新时间:2023-11-04 09:35:49 26 4
gpt4 key购买 nike

我有 Spring Boot REST Controller ,其 header 可以有超过 1 个值:

@RestController
@RequestMapping(value = "/example", headers = {"version=v1", "version=v2"})
@Api(value = "Example API")
public class ExampleController {

并使用Springfox实现了Swagger。当我加载 Swagger UI 时,我可以从版本标题列表中看到并仅选择 v1 选项。如何在 Swagger UI 中显示要选择的所有 header 值?如何更改 Swagger UI 列表中的默认 header 值?

最佳答案

在 Controller 方法上使用 ApiImplicitParams:

@ApiImplicitParams({
@ApiImplicitParam(name = "version", allowableValues="v1,v2", required = false, dataType = "String", paramType = "header")
})

allowableValues :

  1. To set a list of values, provide a comma-separated list. For example: first, second, third.
  2. To set a range of values, start the value with "range", and surrounding by square brackets include the minimum and maximum values, or round brackets for exclusive minimum and maximum values. For example: range[1, 5], range(1, 5), range[1, 5).
  3. To set a minimum/maximum value, use the same format for range but use "infinity" or "-infinity" as the second value. For example, range[1, infinity] means the minimum allowable value of this parameter is 1.

关于java - Swagger UI 不显示所有 header 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56531317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com