Generate openapi 3 spec
from json
request and responses of REST APIs
.
For macOS -> https://docs.docker.com/docker-for-mac/install/
- Git clone the repo.
mkdir -p go
cd go
git clone git@github.com:alokic/sdkgen.git
cd sdkgen
- Build docker image
docker build -t sdkgen .
-
Generates
openapi
specsIn following example,
openapi
specs forjsons
in./examples/inputs/nested
are generated in/tmp/openapi
.
docker run -v ${PWD}/examples:/examples -v /tmp:/tmp sdkgen openapi -i /examples/inputs/nested -o /tmp/openapi
-
Generates SDK
In following example
sdk
inpython
is generated in/tmp/sdk/python
directory from/tmp/openapi/main.yaml
generated in step 7.
docker run -v ${PWD}/examples:/examples -v /tmp:/tmp sdkgen sdk -i /tmp/openapi/main.yaml -o /tmp/sdk -g python
In following example, sdk
is generated with configs
defined in ./examples/config/python.json
.
docker run -v ${PWD}/examples:/examples sdkgen sdk -i /tmp/openapi/main.yaml -o /tmp/sdk -g python -c /examples/config/python.json
# Install go
$ brew install go@1.12
# Install dep (golang package manager)
$ brew install dep
# install openapi generator. Refer
$ brew install openapi-generator
- Make sure GOPATH is properly set.
If you are new to
golang
then,
makdir -p $HOME/go
echo 'export GOPATH=$HOME/go' >>~/.bash_profile
mkdir -p $GOPATH/src $GOPATH/pkg $GOPATH/bin
- Set PATH
export PATH=$PATH:$GOPATH/bin
- Git clone the repo.
mkdir -p $GOPATH/src/github.com/alokic
cd $GOPATH/src/github.com/alokic
git clone git@github.com:alokic/sdkgen.git
cd sdkgen
- Check all deps are there by running below
dep ensure
- Build the app
make build
ctl
gets installed in $GOPATH/bin
- Help
ctl --help
-
Generates
openapi
specsIn following example,
openapi
specs forjsons
in./examples/inputs/nested
are generated in/tmp/openapi
.
ctl openapi -i ./examples/inputs/nested -o /tmp/openapi
-
Generates SDK
In following example
sdk
inpython
is generated in./examples/sdk/python
directory from/tmp/output/main.yaml
generated in step 7.
ctl sdk -i /tmp/openapi/main.yaml -o /tmp/sdk -g python
In following example, sdk
is generated with configs
defined in .examples/config/python
.
ctl sdk -i /tmp/openapi/main.yaml -o /tmp/sdk -g python -c ./examples/config/python.json
make test
For details check: Openapi Codegen
openapi-generator config-help -g python
openapi-generator generate -i <input_file_path> -g python -o <output_folder> --enable-post-process-file