简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM