swagger2x

Description

swagger2x is a Python tool that generate implementations based on templates from JSON files. It uses the jinja2 templates engine.

Table of Contents

Installation

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.

Usage

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.

Templates

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: GenericStack

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.

Template directory structure

The templates can be found at /src/templates the following structure is defined:

DevelopmentProcess

New templates can be added by:

Available Templates

IoTivity Server
PythonFlask
OAS2PahoPy
OAS2SDF
SDF2OAS

Jinja2 template information

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: