swagger-maven-plugin
swagger-maven-plugin copied to clipboard
Add support for responses containing Generic Maps & Lists
Add support for responses of type Map & List. As well as response Pojos containing Maps & Lists
Example1:
@ApiOperation(response=Foo.class, responseContainer="Map[String,Foo]")// or responseContainer="Map[Integer,Foo]"
public Response myMethod(){...}`
Example2:
@ApiOperation(response=Foo.class, responseContainer="List[Foo]")
public Response myMethod(){...}`
Example3:
public class Bar {
private Map<String, Elvis> someMapOfPojos;
private List<Elvis> someListOfPojos;
}
@ApiOperation(response=Bar.class)
public Response myMethod(){...}`
Example4:
public class Bar {
private List<Map<String, Elvis>> someListOfMaps;
}
@ApiOperation(response=Bar.class)
public Response myMethod(){...}`
+1
@dkirrane @ywilkof
I've hit this issue also. It's really a limitation of swagger-core. Yes, swagger-maven-plugin
could abstract the pain a little bit. If you feel inclined to work on a PR before I or @kongchen can get to it, feel free. :)
For a temporary workaround, you could create an empty shim/hinting class that represents your concrete implementation. This is what I've done in places where I've encountered the problem.
Workaround example:
@ApiOperation(response=StringFooMap.class)
public class StringFooMap extends Map<String, Foo>{}
Bumping with a request to continue looking into this. Just received this issue with another style of generic, so requesting that this be investigated for all generics.
While @who's workaround does work for the purposes of swagger, this adds bloat to the project that still remains a problem inevitably.
+1 I'm also unable to see the generic types in the response. But using swagger-core i'm able to see those generic types in response.
I also have this problem - sample code:
@ApiOperation()
public List<Person> myMethod(){...}
Swagger-core renders the response type as a list of "Person" objects but swagger-maven-plugin renders a list of "object"
+1
+1