Search code examples
javaswaggerjax-rsopenapi

Given an *existing* Jersey Jax-RS application, is there a way to generate OpenAPI 3.x JSON/Yaml?


I have an existing Java application that previously has never used Swagger, OpenAPI, etc to create a API specification. So they have the javax.ws.rs.* annotations that specify the API contract for the application.

I'd like to generate a swagger or openapi specification JSON/YAML file for each project using maven.

Does anyone know how to accomplish this?

Is there maybe some Maven plugin you can use to do something like:

mvn someplugin:generateOpenApiJsonUsingOnlyJaxRsAnnotations

And the output would be target/generated-resources/openapi.json.

I know there is the swagger-maven-plugin plugin... but isn't that the reverse direction? Meaning it takes in a OpenAPI json/yaml and produces java classes?

Is there some way to go the other direction at compile time where you take the Jax-RS annotations and produce a openapi json/yaml?

Most importantly, when I say "Existing Jax-RS" application... that means I cannot go in and add a bunch of swagger @Api annotations all over the place. It would be the preference not to have to change the server side of the equation in order to generate the Api client from these Jax-RS service applications.


Solution

  • See this answer here

    How to generate swagger spec from from JAX RS annotated interface?

    Which links to here

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

    So basically there is no way to automatically generate it. You have to put annotations on everything.

    I would LOVE to be wrong about that, because it sucks having to add all these annotations to old code. I'd never get anyone's buy in do that.

    I created https://github.com/kongchen/swagger-maven-plugin/issues/894 with a new feature request.