【问题标题】:Specify options available on API endpoint for a path variable with Swagger in Spring Boot在 Spring Boot 中使用 Swagger 为路径变量指定 API 端点上可用的选项
【发布时间】:2018-07-24 07:16:16
【问题描述】:
我有以下控制器方法
@ApiOperation(value = "Send a signin request with a provider")
@GetMapping("/{provider}/signin")
public void signIn(@PathVariable String provider, HttpServletResponse response) {
service.signIn(provider, response);
}
我想知道的是是否有指定可能值的方法,可以在提供者路径变量中传递。
在 Swagger 文档中,我看到了一些关于枚举的信息,但我不知道如何在我的 Spring Boot 应用程序上使用它。
在 SpringFox 文档中,我找不到 enum 这个词。
提前致谢
【问题讨论】:
标签:
spring-boot
swagger-2.0
path-variables
【解决方案1】:
这里是生成可用选项的示例代码。此示例显示如何多选可用选项。只需使用 String 而不是 List 进行单选
@GetMapping(value = "/request/......", produces = {"application/xml"})
public ResponseEntity<?> createMandate(@NotNull @ApiParam(value = "Test
Case", required = true, allowableValues = "happy-path, dirty-path, wrong-
path") @RequestParam(value = "TestCase", required = true) List<String>
testCases,
@NotNull
@ApiParam(value = "Another Text Field input") @RequestParam(value =
"CustomerMSISDN", required = true) String customerMsisdn) {
return ??
}