Python project generator from a swagger file
codegenit is a development tool for use with "Specification First REST APIs"
Given a OpenAPI specification file (fka swagger) a skeleton server stub project is created. On subsequent runs, the project will be updated as needed from the newly generated stub project.
__init__.py
, __main__.py
, encoder.py
, and util.py
are copied from the CODEGEN_DIR to the PROJECT_DIR.swagger.yaml
file)After the initial run, the project can be started:
python -m PROJECT_DIR
from xxx import xxx
statements are updated for each of the PROJECT_DIR/controllersimport
statements are added for each of the PROJECT_DIR/controllersswagger.yaml
file)python3 -m venv venv
source venv/bin/activate
pip install codegenit
wget --output-document api.yml https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml
codegenit --check
codegenit
$ codegenit --help
usage: codegenit [-h] [-c CODEGEN_DIR] [-p PROJECT_DIR] [-s SWAGGER_FILE] [-u]
[--check]
Generate a python project from a swagger file.
optional arguments:
-h, --help show this help message and exit
-c CODEGEN_DIR, --codegen_dir CODEGEN_DIR
A folder in which to place the codegend project. (default: ./swagger_codegen/)
-p PROJECT_DIR, --project_dir PROJECT_DIR
A folder in which to place the codegend project. (default: ./)
-s SWAGGER_FILE, --swagger_file SWAGGER_FILE
A folder in which to place the codegend project. (default ./api.yml)
-u, --update_args Update the function arguments in the project_dir. (default: warn only)
--check Run in check mode, no changes to PROJECT_DIR. (except trailing whitespace removal)
(venv) ➜ codegenit_test codegenit
[ deleted ] EXISITNG CODEGEN DIRECTORY
[ created ] CODEGEN DIRECTORY
[ running ] CODEGEN DOCKER CONTAINER
[ exists ] /Users/bthornto/github/codegenit_test/swagger_server
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/__init__.py
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/__main__.py
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/encoder.py
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/util.py
[ updated ] /Users/bthornto/github/codegenit_test/swagger_server/swagger
[ updated ] /Users/bthornto/github/codegenit_test/swagger_server/models
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/controllers
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/controllers/__init__.py
[ created ] /Users/bthornto/github/codegenit_test/swagger_server/controllers/pets_controller.py