Skip to main content

A simple python program to generate OpenApi documentation by supplying request/response bodies.

Project description

pytest

InducOapi

A simple python module to generate OpenAPI Description Documents by supplying request/response bodies.

Motivation

Sometimes you have a fully functioning HTTP service without OpenAPI documentation. At some point in time, others may need to use your service. Writing the documentation by hand is a pain and can feel like an overwhelming job for complex services. inducoapi helps you generate your OpenAPI Description Documents by taking as input request/response examples plus some other information.

The generated OpenAPI documentation is validated with openapi3.

Warning: This program also generates the example fields in OpenAPI schemas by default. If you have sensible data in your request/response files, disable this feature with --no-example.

Installation

With pip:

pip install inducoapi

With poetry.

git clone git@github.com:TheWall89/inducoapi.git
cd inducoapi
poetry install

Usage

From CLI

inducoapi provides its own help. Check it out with:

python -m inducoapi -h

Let's consider a simple case: you have an HTTP service managing employees. We want to generate OpenAPI spec for a GET on all the employees, returning a 200 status code:

python -m inducoapi GET /employees 200
output
openapi: 3.0.0
info:
  title: Generated by InducOapi
  version: v1
paths:
  /employees:
    get:
      responses:
        200:
          description: ''

Now, a GET request with an empty response is not quite useful. Let's add an argument with a JSON file containing a response example. Input examples can be found in examples.

python -m inducoapi GET /employees 200 --response examples/employees.json
output
openapi: 3.0.0
info:
  title: Generated by InducOapi
  version: v1
paths:
  /employees:
    get:
      responses:
        200:
          description: ''
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                      example: 1
                    name:
                      type: string
                      example: Dwight Schrute
                    role:
                      type: string
                      example: salesman

Finally, let's try a POST request with both request and response examples.

python -m inducoapi POST /employees 201 --request examples/new_employee_req.json --response examples/new_employee_resp.json
output
openapi: 3.0.0
info:
  title: Generated by InducOapi
  version: v1
paths:
  /employees:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  example: Michael Scott
                role:
                  type: string
                  example: manager
      responses:
        201:
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    example: 4
                  name:
                    type: string
                    example: Michael Scott
                  role:
                    type: string
                    example: manager

If you want to directly write the generated OpenAPI spec in a YAML file, just add --output openapi.yaml

From python

test_inducoapi.py provides usage examples of the module from python.

TODO list

  • Add support for request/response files in YAML
  • Add support for application/yaml content
  • Customize title and version in info
  • Package module
  • Generate resource definitions
  • Add support for headers
  • Add support for links
  • Add support for format

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inducoapi-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inducoapi-1.0.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file inducoapi-1.0.0.tar.gz.

File metadata

  • Download URL: inducoapi-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.0 CPython/3.6.10 Linux/5.8.12-zen1-1-zen

File hashes

Hashes for inducoapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 274a9cb51b16f22c971ef603345b1c2c1c74c91b17ec65dd10527285514f3927
MD5 01782796f255e139be8846c070788465
BLAKE2b-256 18b9e2d21abf9bc6cfba60fc4e4ae02e901f6bc5720ca29253801cf1595858e1

See more details on using hashes here.

File details

Details for the file inducoapi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: inducoapi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.0 CPython/3.6.10 Linux/5.8.12-zen1-1-zen

File hashes

Hashes for inducoapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac78b237b974f25fcd7cea01dae2b564588ee9dced568a8442b3d2249bd1ff51
MD5 4dafef1fad88f0d77b8d151cd1230e07
BLAKE2b-256 d439df23b91163d5c663852e415c1f0149515700077dc70bdc8c6dc74845ae40

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page