InducOapi
A simple python module to generate OpenAPI Description Documents by supplying request/response bodies.
Contributions for new features, fixes or improvements are welcome. Feel free to send a pull request.
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 openapi-spec-validator.
Warning: This program also generates the example fields in OpenAPI schemas by default. If you have sensitive 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 command. You can simply execute it with
inducoapi
If you get a command not found error, try to activate your virtualenv or run poetry shell first.
You can also run inducoapi in the classic way:
python -m inducoapi
Help
inducoapi provides its own help. Check it out with:
python -m inducoapi -h
Examples
Let's consider a simple case: you have an HTTP service managing employees. We want to generate the OpenAPI Description Document 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
Let's add a parameter to filter the employees by name.
python -m inducoapi GET /employees 200 --response examples/employees.json --parameter name,query
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
parameters:
- name: name
in: query
required: false
description: ''
schema: { }
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 Description Documents to a YAML file, just
add --output openapi.yaml
From python
test_inducoapi.py provides usage examples of the module from python.
Dev
If you have https://taskfile.dev/:
task test
Otherwise:
poetry install --with=dev
poetry run pytest
TODO list
- Add support for request/response files in YAML
- Add support for
application/yamlcontent - Customize title and version in info
- Package module
- Support for
$refin response schemas - Add support for
parameters -
Add support for(I don't think it is very useful)links -
Add support for(hard to infer)format
Metadata
Release files for inducoapi 2.1.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| inducoapi-2.1.14.tar.gz | 9.4 kB | Without provenance | Details for inducoapi-2.1.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| inducoapi-2.1.14-py3-none-any.whl | Python 3 | none | any | Details for inducoapi-2.1.14-py3-none-any.whl |
Total release size: 20.9 kB
Release files / inducoapi-2.1.14.tar.gz
| Download URL | inducoapi-2.1.14.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97c2771935ec1042525d1c2d1009f48bc142b85b470a84e4dcb0f5b64816be2a
|
|
BLAKE2b-256 checksum How to use checksums |
d144dd73bf837fba49c5a59f7220080eb7d959cc4905ef51f0c3779b008f4bfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1018-azure
|
Release files / inducoapi-2.1.14-py3-none-any.whl
| Download URL | inducoapi-2.1.14-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08ff9a9b2ddad9bd0e6eb1245db41a7816b93494f9e65193ca937f626ac2ab2d
|
|
BLAKE2b-256 checksum How to use checksums |
d5881e779878299c458b87e101f2e6d054c9f99c52007b84fe825d9548d5309d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1018-azure
|
Security for inducoapi 2.1.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.