如何大摇大摆地下拉可能的值
How to get drop down for possible values in swagger
嗨,我有休息 API 并使用 swagger 来测试这个 API。
下面是我的 API.
@RequestMapping(value = "/api/test", method = RequestMethod.POST)
public void test(String string){
// body
}
参数的可能值为 "Database" 或 "Cache"。
所以我想在大摇大摆的视图中下拉。
我已经进行了 google 搜索,但找不到如何使用 java 实现。
您可以使用可能的值注释您的参数
@RequestMapping(value = "/api/test", method = RequestMethod.POST)
public void test(@ApiParam(allowableValues = "one, two, three") String string) {
// body
}
您必须使用 Enum 作为您的方法参数,而不是 String。请参阅以下参考资料:
@RequestMapping(value = "/api/test", method = RequestMethod.POST)
public void test(TestEnum enum) {
// body
}
下面是您的 TestEnum:
public enum TestEnum {
Dropdown1("DropDown1"),
DropDown2("DropDown2");
private String str;
TestEnum(String str){
this.str = str;
}
public String getStr() {
return str;
}
}
嗨,我有休息 API 并使用 swagger 来测试这个 API。
下面是我的 API.
@RequestMapping(value = "/api/test", method = RequestMethod.POST)
public void test(String string){
// body
}
参数的可能值为 "Database" 或 "Cache"。
所以我想在大摇大摆的视图中下拉。
我已经进行了 google 搜索,但找不到如何使用 java 实现。
您可以使用可能的值注释您的参数
@RequestMapping(value = "/api/test", method = RequestMethod.POST)
public void test(@ApiParam(allowableValues = "one, two, three") String string) {
// body
}
您必须使用 Enum 作为您的方法参数,而不是 String。请参阅以下参考资料:
@RequestMapping(value = "/api/test", method = RequestMethod.POST)
public void test(TestEnum enum) {
// body
}
下面是您的 TestEnum:
public enum TestEnum {
Dropdown1("DropDown1"),
DropDown2("DropDown2");
private String str;
TestEnum(String str){
this.str = str;
}
public String getStr() {
return str;
}
}