问题
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