forked from loafle/openapi-generator-original
[docker] Add container docs and example usage
This commit is contained in:
@@ -111,16 +111,41 @@ After cloning the project, you can build it from source with this command:
|
||||
mvn package
|
||||
```
|
||||
|
||||
### Homebrew
|
||||
|
||||
To install, run `brew install swagger-codegen`
|
||||
|
||||
Here is an example usage:
|
||||
```
|
||||
swagger-codegen generate -i http://petstore.swagger.io/v2/swagger.json -l ruby -o /tmp/test/
|
||||
```
|
||||
|
||||
### Docker
|
||||
#### Build and run 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`:
|
||||
|
||||
```
|
||||
git clone https://github.com/swagger-api/swagger-codegen
|
||||
cd swagger-codegen
|
||||
./run-in-docker.sh 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:
|
||||
|
||||
```
|
||||
./run-in-docker.sh help # Executes 'help' command for swagger-codegen-cli
|
||||
./run-in-docker.sh langs # Executes 'langs' command for swagger-codegen-cli
|
||||
./run-in-docker.sh /gen/bin/go-petstore.sh # Builds the Go client
|
||||
./run-in-docker.sh generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml \
|
||||
-l go -o /gen/out/go-petstore -DpackageName=petstore # generates go client, outputs locally to ./out/go-petstore
|
||||
```
|
||||
|
||||
#### Run Docker in Vagrant
|
||||
Prerequisite: install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
|
||||
@@ -133,17 +158,53 @@ cd /vagrant
|
||||
./run-in-docker.sh mvn package
|
||||
```
|
||||
|
||||
#### Public Docker image
|
||||
#### Public Pre-built Docker images
|
||||
|
||||
https://hub.docker.com/r/swaggerapi/swagger-generator/
|
||||
* Swagger Generator: https://hub.docker.com/r/swaggerapi/swagger-generator/
|
||||
* Swagger Codegen : https://hub.docker.com/r/swaggerapi/swagger-codegen/
|
||||
|
||||
### Homebrew
|
||||
To install, run `brew install swagger-codegen`
|
||||
##### 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):
|
||||
|
||||
Here is an example usage:
|
||||
```
|
||||
swagger-codegen generate -i http://petstore.swagger.io/v2/swagger.json -l ruby -o /tmp/test/
|
||||
# Start container and save the container id
|
||||
CID=$(docker run -d swaggerapi/swagger-generator)
|
||||
# allow for startup
|
||||
sleep 5
|
||||
# Get the IP of the running container
|
||||
GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $CID)
|
||||
# Execute an HTTP request and store the download link
|
||||
RESULT=$(curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
|
||||
"swaggerUrl": "http://petstore.swagger.io/v2/swagger.json"
|
||||
}' 'http://localhost:8188/api/gen/clients/javascript' | jq '.link' | tr -d '"')
|
||||
# Download the generated zip and redirect to a file
|
||||
curl $RESULT > result.zip
|
||||
# Shutdown the swagger generator image
|
||||
docker stop $CID && docker rm $CID
|
||||
```
|
||||
|
||||
In the example above, `result.zip` will contain the generated client.
|
||||
|
||||
##### Swagger Codegen 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:
|
||||
|
||||
```
|
||||
docker run --rm -v ${PWD}:/local swagger-api/swagger-codegen generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l go \
|
||||
-o /local/out/go
|
||||
```
|
||||
|
||||
The generated code will be located under `./out/go` in the current directory.
|
||||
|
||||
## Getting Started
|
||||
|
||||
To generate a PHP client for http://petstore.swagger.io/v2/swagger.json, please run the following
|
||||
|
||||
Reference in New Issue
Block a user