Swagger Codegen Using Docker
Development in docker
You can use run-in-docker.sh
to do all development. This script maps your local repository to /gen
in the docker container. It also maps ~/.m2/repository
to the appropriate container location.
To execute mvn package
:
Build artifacts are now accessible in your working directory.
Once built, run-in-docker.sh
will act as an executable for swagger-codegen-cli. To generate code, you’ll need to output to a directory under /gen
(e.g. /gen/out
). For example:
Standalone generator Development in docker
See standalone generator development
Run Docker in Vagrant
Prerequisite: install Vagrant and VirtualBox.
Public Pre-built Docker images
- https://hub.docker.com/r/swaggerapi/swagger-generator/ (official web service)
- https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/ (official CLI)
Swagger Generator Docker Image
The Swagger Generator image can act as a self-hosted web application and API for generating code. This container can be incorporated into a CI pipeline, and requires at least two HTTP requests and some docker orchestration to access generated code.
Example usage (note this assumes jq
is installed for command line processing of JSON):
In the example above, result.zip
will contain the generated client.
Swagger Codegen CLI Docker Image
The Swagger Codegen image acts as a standalone executable. It can be used as an alternative to installing via homebrew, or for developers who are unable to install Java or upgrade the installed version.
To generate code with this image, you’ll need to mount a local location as a volume.
Example:
(On Windows replace ${PWD}
with %CD%
)
The generated code will be located under ./out/go
in the current directory.