pvm14
pvm14

Reputation: 544

Documenting existing JAX-RS implementation with Swagger without annotating it

I would like to generate the Swagger documentation for an existing JAX-RS implementation without having to modify my code at all. I'd love not to have to introduce any kind of Swagger annotations decorating my classes.

Here

https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X.

they seem to suggest that after configuring your application to use Swagger you have to annotate your code for swagger to be able to generate swagger.json. Am I right? Are annotations needed? If not, I don't understand very well their purpose

Is this magic of documenting your existing JAX-RS application without modifying you code possible?

I've found this http://www.adam-bien.com/roller/abien/entry/jax_rs_get_swagger_json.

Could this be a solution?

Upvotes: 2

Views: 1362

Answers (1)

Sampada
Sampada

Reputation: 2991

Swagger annotations are required to add the documentation to your JAX-RS implementation. The purpose is to define your API operations and parameters, what is their meaning and purpose.

The link you shared appears to be some sort of a hack mechanism. But i don't see how any code can find out the intent of your API unless you explicitly declare it.

If you need to minimize swagger annotation usage, there are 2 ways to do this:

  1. Only use @Api at class level and do not use method level annotations. This will render a basic swagger.json with a listing of your GET/POST etc APIs.

  2. Write an interface and use annotations here. You API class needs to just extend this interface then. This will reduce impact on your existing class.

Hope this helps.

Upvotes: 4

Related Questions