swagger-maven-plugin icon indicating copy to clipboard operation
swagger-maven-plugin copied to clipboard

Add support for responses containing Generic Maps & Lists

Open dkirrane opened this issue 9 years ago • 7 comments

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(){...}`

dkirrane avatar Jun 11 '15 13:06 dkirrane

+1

ywilkof avatar Jun 23 '15 21:06 ywilkof

@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>{}

who avatar Jul 02 '15 06:07 who

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.

ihgann avatar Mar 02 '16 01:03 ihgann

+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.

Jeevi21 avatar Jul 11 '16 08:07 Jeevi21

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"

lalpert avatar Aug 02 '16 06:08 lalpert

+1

SenZh avatar Oct 25 '17 02:10 SenZh

+1

Ahsan-Aziz-Ishan avatar Feb 23 '23 07:02 Ahsan-Aziz-Ishan