how to add Swagger resource definitions dynamically?

362 views
Skip to first unread message

Denis Sukhoroslov

unread,
Dec 3, 2016, 6:46:59 AM12/3/16
to Swagger
Hi,

I have several static REST resources implemented with Jersey 2.23.x. Their implementation classes are annotated with Swagger @Api annotations and they're proprly exposed in swagger.json. I also have a number of dynamically generated REST resources created via Jersey Resource.Builder API. How can I register them with Swagger?
I'm implementing ReaderListener interface and want to register my dynamic REST resources in its afterScan method via swagger.addDefinition() API. Is it the right way to go? If yes, how can I build Model to register it with Swagger properly?

Thanks, Denis.

Denis Sukhoroslov

unread,
Dec 19, 2016, 6:34:29 AM12/19/16
to Swagger
Well, I was able to generate resource definitions dynamically using io.swagger.models.Swagger API from my ReaderListener.afterScan() method. But it seems to work properly only once: before the first swagger.json file generation. If I change my resources several times in a session, the ReaderListener.before/afterScan methods are invoked on every reload. But the resulting swagger.json file does not change and contains resource definitiions produced on the first scan only. It looks like Swagger caches the definitions (or, the whole json/yaml generated content ?) somewhere. Is there any method to clean the cache somehow and force Swagger to re-generate resource definitions from very beginning?

Thanks, Denis.

sukrut wagh

unread,
Nov 14, 2017, 8:17:25 AM11/14/17
to Swagger
That's cool, Even I am looking to implement something on the same lines. May i request you to share your code snippet?

Regards,
Sukrut
Reply all
Reply to author
Forward
0 new messages