Generate Swagger.json programatically?

676 views
Skip to first unread message

Aman Jain

unread,
Oct 19, 2015, 2:52:33 PM10/19/15
to Swagger
Hi Team,

I am new to Swagger, so please accept my apologies for any basic questions!

We have an legacy application where we use single java servlet to serve multiple REST web services based on path param. Based on different value of path param, we tend to process it in different way and return the response. I know this is not the best way of coding the application but this is a legacy application which can't be modified and have to work on building documentation for multiple REST web services that in backend calls to single java servlet.

I need to know, how this can be achieved via swagger? Is there a way to programmatically generate swagger.json through my application (based on different combinations of REST web services) and then I can feed that JSON to Swagger-UI to beautifully document it?

Any help in this regard shall be greatly appreciated.

Thanks in advance!

Regards,
Aman

Ron Ratovsky

unread,
Oct 20, 2015, 12:54:46 AM10/20/15
to Swagger
Hi Aman,

If it's a singleI servlet describing multiple endpoints, I'm afraid you're out of luck with regard to code integration.
We released today swagger-core 1.5.4 that has servlet integration, but it assumes one servlet per endpoint.

That said, if the API is not insanely big, you can still document it by writing the swagger.json/.yaml manually.
Since this is a legacy API, I assume it doesn't change often so it wouldn't be too difficult to maintain.

Hope this helps,
Ron

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

Aman Jain

unread,
Oct 20, 2015, 1:56:31 AM10/20/15
to swagger-sw...@googlegroups.com

Thanks for your response.

Is there an API or method which I can call within Swagger to build swagger.json for my end points OR I have to build it manually through my code?

Thanks,
Aman

You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/wqBXfAbHbu0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron Ratovsky

unread,
Oct 20, 2015, 6:22:53 PM10/20/15
to Swagger
The swagger-models module contain a Swagger structure that's built and then serialized into swagger.json.
The Reader classes do the actual code parsing and build the Swagger object. You have a Reader for jax-rs and one for servlets.
Perhaps looking at those would help in deciding whether you'd like to invest time creating a Reader of your own.
Keep in mind they both depend on swagger-annotations which may not be useful for your case, but if you end up writing your own Reader, you could obviously use your own annotations and processing.
Reply all
Reply to author
Forward
0 new messages