Skip to content

alokic/sdkgen

Repository files navigation

sdkgen

Generate openapi 3 spec from json request and responses of REST APIs.

Docker Setup

Pre-requisites

Install docker

For macOS -> https://docs.docker.com/docker-for-mac/install/

Build

  1. Git clone the repo.
    mkdir -p go

    cd go

    git clone git@github.com:alokic/sdkgen.git

    cd sdkgen
  1. Build docker image
    docker build -t sdkgen .
  1. Generates openapi specs

    In following example, openapi specs for jsons 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
  1. Generates SDK

    In following example sdk in python 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

Local Setup

Pre-requisites

    # Install go
    $ brew install go@1.12

    # Install dep (golang package manager)
    $ brew install dep

    # install openapi generator. Refer
    $ brew install openapi-generator

Build

  1. 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
  1. Set PATH
    export PATH=$PATH:$GOPATH/bin
  1. 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
  1. Check all deps are there by running below
   dep ensure
  1. Build the app
   make build

ctl gets installed in $GOPATH/bin

  1. Help
    ctl --help
  1. Generates openapi specs

    In following example, openapi specs for jsons in ./examples/inputs/nested are generated in /tmp/openapi.

    ctl openapi -i ./examples/inputs/nested -o /tmp/openapi
  1. Generates SDK

    In following example sdk in python 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

Tests

    make test

Openapi generator commands

For details check: Openapi Codegen

Config options for a language

    openapi-generator  config-help -g python

Generate code

    openapi-generator generate   -i <input_file_path> -g python -o <output_folder> --enable-post-process-file