Can Swagger @APIOperation allow to specify a list of list in Java?

安稳与你 提交于 2019-12-07 08:40:51

问题


I have a method in a Java class with signature like below and I want to add Swagger Rest documentation for it.

public List<List<MyCustomClass>> getMyCustomClasses(String id){
//
}

I want to know if there is a way to have either response or responseContainer to return List of List objects? Something like below?

@ApiOperation(value = "find MyCustomClass objects by id", response =MyCustomClass.class , responseContainer =   "List<List>")

I have no issues in generating swagger docs if the response of the method is just List where I could specify response =MyCustomClass.class , responseContainer = "List" but having problem only if it is List of List as return type.

Thanks

Ravi


回答1:


In order to do this you can simply create a template class like this:

public class TempClass {
   private List<someClass> listOfClass;
   public List<someClass> getListOfClass() {
      return listOfClass;
   }
   public void setListOfClass(List<someClass> listOfClass) {
      this.listOfClass = listOfClass;
   }
}

or even more complicated like this:

public class TempClass {
   private List<List<List<someClass>>> listOfList;
   public List<List<List<someClass>>> getListOfList(){ 
      return listOfList;
   }
   public void setListOfList(List<List<List<someClass>>> listOfList) {
      this.listOfList = listOfList;
   }
}

And at the end get this class as a response to the annotation above the method like this:

@ApiOperation(response = TempClass.class)

you should also specify the return type of the method as the TempClass

There is another issue that discussed a same issue here



来源:https://stackoverflow.com/questions/24557640/can-swagger-apioperation-allow-to-specify-a-list-of-list-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!