Closed dclim closed 9 years ago
I just ran into this today in version 1.0.4.1, while trying to annotate an endpoint with a responseType of Map<Type1, Type2>. I'm getting UnsupportedOperationException: Generic response types are not supported for custom @returnType, only collection types are allowed.
Given that Java Maps aren't Collections, is it currently impossible to represent this?
@davidclarencelim can you give me an example of the method signature you have the problem with?
@buzzkillington again can you show me the method signature you are using so I can be clear about your issue. Swagger spec 1.2 doesnt support map types, one option is to support a list of entry objects which have a key and value, but that is unlikely to match what your rest framework will accept as input, an alternative is to have something that can define the supported key names e.g. a series of javadoc tags like
@mapKey mykey string @mapKey mykey2 int
so I can use that to build the model object that can be submitted.
@conorroche I just started using Swagger/swagger-jaxrs-doclet yesterday, in a Dropwizard project. My method actually returns a Response, but I'm trying to use @responseType to describe the entity contained in the Response: a Map<FooEnum, FooData>
; in this case, the key type happens to be an enum, and the value type is a domain object with a couple fields. To help clarify, the JSON-serialized output looks like {"FOO_1":{"fieldA":"valueA","fieldB":"valueB"},"FOO_2":{"fieldA":"valueA2","fieldB":"valueB2"}}
.
@buzzkillington thanks for the clarification, I should be able to have it document the return type as Map without an error fairly quickly, I have an idea how to support what you really want but this is more complicated so will take some time, I hope to have some time at the weekend to work on it
@conorroche Cool, thanks - look forward to checking it out!
@conorroche Perhaps something like this:
class Batch<T> {
Set<T> items;
String nextToken;
}
class Item {
String id;
String desc;
}
for @responseType com.dlim.Batch<Item>
(or something similar..), I'd love to be able to pass enough information that I could generate a model schema in swaggerUI or similar that looked like this:
{
"items" : [ { "id" : "", "desc" : "" } ],
"nextToken" : ""
}
Is this even possible?
@davidclarencelim I have now added support for generics in @responseType to the latest snapshot, including the use case you described
@buzzkillington Ive fixed it so now it will at least process a Map method but it will output the response type as Map which is an undocumented model. Here is an example:
/* * @responseType java.util.Map<java.lang.String, java.lang.Integer> / @GET @Path("/g") public Response getG() { return null; }
since swagger doesnt support maps the only way i can think of documenting it is to support a javadoc tag that can include a fragment of the model json either directly or via an external file. If this sounds reasonable i can open a separate issue for that.
@conorroche That's awesome, thank you! I haven't had a chance to test it out yet but I'll let you know if anything comes up. Appreciate the fast turnaround.
closing as I believe this has been fixed
Any plan to add support for generics for custom @responseType?
Appreciate the work you've done. Thanks!