如何让 Swagger UI 的参数成为下拉菜单而不是文本输入 [英] How to get Swagger UI's Parameter to be Dropdown menu instead of Text Input

查看:45
本文介绍了如何让 Swagger UI 的参数成为下拉菜单而不是文本输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 swagger 来显示我的 RESTApi,API 的一个参数将字符串作为输入并将其转换为枚举值.有没有办法在 Swagger UI 上显示下拉菜单,而不是文本输入字段,以便用户只能选择枚举值中的字符串值.

I am using swagger to display my RESTApi, one parameter of an API takes string as input and convert it to enum value. Is there any way to display a drop-down menu on the Swagger UI instead of having a text input field so that users can only select the string values within the enum value.

推荐答案

关键是要使用allowableValues@ApiParam 注释中.

The key is to use allowableValues in the @ApiParam annotation.

演示结果:

http://petstore.swagger.io/#!/pet/findPetsByStatus

查看 pet/findByStatus,它不是下拉菜单,但输入受限于多选框.

Check out pet/findByStatus, it's not a dropdown but input is limited in the multi-select box.

这篇关于如何让 Swagger UI 的参数成为下拉菜单而不是文本输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆