Swagger and generic interfaces

已查看 98 次
跳至第一个未读帖子

Harald Bittermann

未读,
2015年7月1日 02:45:172015/7/1
收件人 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

未读,
2015年7月5日 15:51:522015/7/5
收件人 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

未读,
2015年7月6日 02:56:542015/7/6
收件人 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

未读,
2015年7月6日 03:03:142015/7/6
收件人 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.
回复全部
回复作者
转发
0 个新帖子