swagger2x is a Python tool that generate implementations based on templates from JSON files. It uses the jinja2 templates engine.
This tool is Python3 based.
Installation of the tool is makin a clone of the repository and use the tool relative of where the repository is located on your system. To install the dependencies:
run pip3 install -U -r requirements.txt
to install the dependencies.
Swagger2x is an command line tool. To run the tool enter this on the (bash) command line:
python3 swagger2x.py <options>
use -h to see all the options.
note: see/use DeviceBuilder for usage of this tool in the development chain.
To run the tooling on windows, install git-bash.
The code generator is using jinja2 templates. Using templates decouples the generated code from looping over the JSON hierarchy.
For code generation the input JSON file is a swagger2.0 file. The hierarchy traversed is the swagger2.0 file constructs in JSON e.g. the end points, methods, query param and payload information is available in the jinja2 template.
The code that can be generated should take into account:
Therefore a template is an mix of the library calls, the supported operating system in the used language mixed with the jinja2 template language to generate the code. jinja2 takes the JSON swagger information and make it iteratable by looping over the end points, methods etc. and uses then the info to fill in the library/os calls in the used language.
The templates can be found at /src/templates the following structure is defined:
New templates can be added by:
The template contents is an mix of the target syntax and jinja2 commands.
Information on implemented commands can be found here.
Information about jinja2 commands can be found at: