swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.93k stars 6.03k forks source link

[JAVA] Generate JSON or YAML api specs from Maven plugin #6303

Open raphael-chir opened 7 years ago

raphael-chir commented 7 years ago
Description

Actually we have to specify in Maven plugin "swagger-codegen-maven-plugin" an "inputSpec" value in plugin execution configuration. I didn't find a way to dynamically generate it from REST resources Spring class instead of a static file or an uri. It supposed that the server is already running to have the specs in v2/api-docs It would be nice if we can build the server jar and the relative REST client jar. So consumers of this REST API are always aware (in a SNAPSHOT case) of specs evolution on the server.

Swagger-codegen version

2.3.0

Suggest a fix/enhancement

Something like this could be useful in the server pom.xml, in an assembler profile for instance :

``

io.swagger swagger-codegen-maven-plugin ${swagger.codegen.version} generate native com.myproject.restdomain1 com.myproject.restdomain2 java src/gen/java/main
thlaegler commented 7 years ago

In my understanding this maven plugin (as the word "codegen" implies) is focused on generating code from an OpenAPI specification (e.g. from a swagger.yaml).

To do the other way around (code to spec) try another maven plugin like https://github.com/kongchen/swagger-maven-plugin or in terms of using Spring try http://springfox.github.io/springfox