Can Swagger @APIOperation specify a list of lists in Java?

I have a method in a Java class with signatures, as shown 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 return either a response or responseContainer in order 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 problem creating documents for swagger if the response of the method is just List where I could specify the answer = MyCustomClass.class, responseContainer = "List", but having a problem only if it is a List of List as the return type.

thank

Ravi

+4
source share
1 answer

To do this, you can simply create a template class as follows:

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

or even harder:

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

:

@ApiOperation(response = TempClass.class)

TempClass

,

-1

Source: https://habr.com/ru/post/1547037/


All Articles