Issue with Swagger api-doc json generation in OSGi (Fuse ESB) container

615 views
Skip to first unread message

Hiren Dutta

unread,
Apr 21, 2014, 12:15:41 PM4/21/14
to swagger-sw...@googlegroups.com
Hi,

I am a newbie in swagger. Need help to understand issues that I am facing with OSGi container (Fuse).

I have created CXF based REST services and deployed in OSGi container as service bundle. Used Swagger API annotations to generate api-docs dynamically. 
Below are my queries and findings that I wanted to get verified.

1. Does api-docs created on the fly for each request or it creates only once and kept it cached. If its get cached, in which path it stores api-docs json in OSGi container?

2. OSGi container supports hot deployment of bundles. If I changed annotated API doc info into service and hot deploy, updated doc is not reflected until I restart the OSGi container. If api docs jason is getting generated dynamically why we need to restart the OSGI container (Fuse) to reflect updated info?

3. lets consider this scenario. 
Bundle-A contains service interface, implementation using cxf and swagger config information. Interface operations and swagger api annotated. (with @Api, @ApiOperation, @ApiParam)
Bundle-B contains all request, response objects and required java models. All request response objects are swagger api annotated. (@ApiModel,@ApiModelProperty)

Api-docs from Bundle-A is getting generated properly but models swagger doc is not getting generated and not reflected into swagger UI. I have checked with the json that are getting generated from OSGi container. Model information is missing into the json. Can you please throw some light on this strange behavior of swagger? Is there any compatibility issue swagger with OSGi?

Regards,
Hiren


Hiren Dutta

unread,
Apr 23, 2014, 6:27:41 AM4/23/14
to swagger-sw...@googlegroups.com
Any suggestion please.. 

tony tam

unread,
Apr 23, 2014, 7:40:37 AM4/23/14
to swagger-sw...@googlegroups.com
Did you build your own swagger bundle?  Are your models being loaded at runtime?  

On Wednesday, April 23, 2014 3:27:41 AM UTC-7, Hiren Dutta wrote:
Any suggestion please.. 

tony tam

unread,
Apr 23, 2014, 8:11:53 AM4/23/14
to swagger-sw...@googlegroups.com
It looks like the swagger cache should be cleared in the bundle activator stop().

com.wordnik.swagger.jersey.listing.ApiListingCache.invalidateCache()

Hiren Dutta

unread,
Apr 24, 2014, 6:47:49 AM4/24/14
to swagger-sw...@googlegroups.com
I have used swagger annotations at REST service interface. Swagger annotations are part of my REST API bundle. (Bundle-A)
  
Yes. Definition of model package to be imported configured at POM maven-bundle-plugin. Bundle contains models (Bundle-B) are being loaded at runtime.

Regards,
Hiren

Hiren Dutta

unread,
Apr 29, 2014, 1:26:19 PM4/29/14
to swagger-sw...@googlegroups.com
any suggestion on #3 please

tony tam

unread,
Apr 29, 2014, 3:49:43 PM4/29/14
to swagger-sw...@googlegroups.com
Hi please send an email to api...@helloreverb.com and we can pass on a sample OSGi bundle.

On Tuesday, April 29, 2014 10:26:19 AM UTC-7, Hiren Dutta wrote:
any suggestion on #3 please

Hiren Dutta

unread,
May 2, 2014, 4:43:22 AM5/2/14
to swagger-sw...@googlegroups.com
Issue#3

Hi Tony,
I have checked with the sample REST GET request. Request Response model attribute information is not getting generated dynamically from service swagger annotations. Same issue I am facing with POST request as well.

HelloRequest.java

@XmlRootElement
@JsonPropertyOrder({"name"})
@ApiModel(value = "HelloRequest",
        description = "Hello Request")
public class HelloRequest {

    @ApiModelProperty(value = "Value of name field", required = true)
    private String name;

    @XmlElement(name = "name")
    @JsonProperty("name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

HelloResponse.java

@XmlRootElement
@JsonPropertyOrder({"helloRes"})
@ApiModel(value = "HelloResponse",
        description = "Hello Response")
public class HelloResponse {

    @ApiModelProperty(value = "Value of Hello response", required = true)
    private String helloRes;

    @XmlElement(name = "helloRes")
    @JsonProperty("helloRes")
    public String getHelloRes() {
        return helloRes;
    }

    public void setHelloRes(String helloRes) {
        this.helloRes = helloRes;
    }

}

Service interface

@Path("/v1/hello/")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @ApiOperation(value = "Name to say Hello",
            notes = "Other Hello notes New content",
            response = HelloResponse.class)
    @ApiResponses(value = {
        @ApiResponse(code = 400, message = "Invalid request supplied"),
        @ApiResponse(code = 404, message = "Name not found")
    })
    public Response sayHello(@ApiParam(value = "Name to whom to say Hello", required = true) @QueryParam(value = "name") String name);

Swagger output is failed to generate Request, Response model properties information in UI.


Please suggest.

Regards,
Hiren

tony tam

unread,
May 2, 2014, 5:02:22 PM5/2/14
to swagger-sw...@googlegroups.com
Hi, I think this is an access issue between the components.  Can you, just for testing, make the HelloResponse model a compile dependency in your service class to ensure it's being loaded there?

Hiren Dutta

unread,
May 3, 2014, 12:48:00 AM5/3/14
to swagger-sw...@googlegroups.com
Hi Tony,
Model classes are getting loaded properly as same set of classes are used for service request and response generation and service is working properly.
It's seems like a bug in new version? Medel (simple and composite) properties are failed to generate in json structure. Please suggest.

reference : Swagger documentation annotation [Step 5: annotate your api]

Regards,
Hiren

tony tam

unread,
May 7, 2014, 11:26:00 AM5/7/14
to swagger-sw...@googlegroups.com
Hi Hiren,
I really need to get logs from your server starting up to see what's wrong.  Consider setting com.wordnik to debug and post the logs (email if private info in them).
Reply all
Reply to author
Forward
0 new messages