2017-08-04 123 views
0

您好我有Rest API,並使用Swagger來測試此API。如何在swagger中獲得可能的值的下拉列表

下面是我的API之一。

@RequestMapping(value = "/api/test", method = RequestMethod.POST) 
public void test(String string){ 
    // body 
} 

參數的可能值是「數據庫」或「緩存」。

所以我想放下在招搖的視野。

我已經通過谷歌搜索,我找不到如何實現與Java。

回答

1

你必須使用枚舉作爲方法的參數,而不是字符串的註釋你的參數。請參見下面的參考:

@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; 
    } 
} 
0

您可以使用可能值

@RequestMapping(value = "/api/test", method = RequestMethod.POST) 
public void test(@ApiParam(allowableValues = "one, two, three") String string) { 
    // body 
} 
+0

它不工作,有文本區域是顯示屏,而不是下拉。 –

相關問題