Swagger and generic interfaces

98 views
Skip to first unread message

Harald Bittermann

unread,
Jul 1, 2015, 2:45:17 AM7/1/15
to swagger-sw...@googlegroups.com
Hi,

we try to extract a proper REST API docu from the following model (shown below). All Rest classes inherit their default GET function from an abstract class.
Swagger-UI shows the available resources properly (in the example below, both GET), but the one, inherited from REST.get, the "wrong" Model (ie ModelJson) is shown. This makes absolutely sense because the ApiResponses annotation on REST.get identifies ModelJson as the  response class.

However, we'd like  the concrete class to show up in our swagger documentation, not the base class. It probably would be possible to override "get" in AnyRest and adapt the annotation. But this is not an option.

Can this issue be addressed with Swagger? And if yes, how?
Thanks in advance.

abstract class ModelJson {
 
int id;
 
Date createdOn;
 
...
}


class AnyJson extends ModelJson {
 
String anyString;
 
...
}


abstract class REST<T extends ModelJson> {


@GET
@Path("/{id: [0-9]*}")
@ApiOperation(value = "get resource", notes = "Gets a single resource from this endpoint.")
@ApiResponses(value = {@ApiResponse(code = HttpServletResponse.SC_OK, message = "OK.", response=ModelJson.class)}
T
get(int id){...};


}




@Path("/any")
@Api(value = "any", description = "Does somthing fancy")
class AnyRest extends REST<AnyJson> {


   
@GET
 
@ApiOperation(value = "Do any action", notes = "this does anything")
 
@ApiResponses(value = {@ApiResponse(code = HttpServletResponse.SC_OK, message = "OK.", response=AnyJson.class)}
   
AnyJson anyFunction(...,...,...){
       
...
   
}
}


Ron Ratovsky

unread,
Jul 5, 2015, 3:51:52 PM7/5/15
to swagger-sw...@googlegroups.com
Which version of swagger-core do you use?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Harald Bittermann

unread,
Jul 6, 2015, 2:56:54 AM7/6/15
to swagger-sw...@googlegroups.com
Our war-project includes 
  
      <dependency>
           
<groupId>com.wordnik</groupId>
           
<artifactId>swagger-jaxrs_2.10</artifactId>
           
<version>1.3.6</version>
       
</dependency>


Which adds a transitive dependency to

    <dependency>
     
<groupId>com.wordnik</groupId>
     
<artifactId>swagger-core_2.10</artifactId>
     
<version>1.3.6</version>
     
<scope>compile</scope>
   
</dependency>

Changing the version would be no big deal if this makes any difference.

Ron Ratovsky

unread,
Jul 6, 2015, 3:03:14 AM7/6/15
to swagger-sw...@googlegroups.com
Okay, that's a relatively old version of swagger-core which I believe did not handle generics too well.

I'd suggest upgrading to the latest version, but it does carry some migration process.
Follow the online guide and try it out. I cannot guarantee it would help your use case, but it's definitely worth a shot.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages