【问题标题】:How to get drop down for possible values in swagger如何在招摇中获得可能的值
【发布时间】:2017-08-04 10:13:21
【问题描述】:

您好,我有 Rest API 并使用 swagger 测试此 API。

下面是我的一个 API。

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

参数的可能值为“数据库”或“缓存”。

所以我想在招摇视图中下拉。

我已经通过谷歌搜索,我找不到如何用java实现。

【问题讨论】:

    标签: java rest web-services swagger swagger-ui


    【解决方案1】:

    您必须使用 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;
        }
    }
    

    【讨论】:

      【解决方案2】:

      你可以用可能的值来注释你的参数

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

      【讨论】:

      • 它不工作,有文本区域显示而不是下拉。
      猜你喜欢
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 2018-07-16
      相关资源
      最近更新 更多