Create Postman JSON API documentation files from Sanic.
Project description
sanic-to-json
Generate a Postman JSON file from a Sanic app. The JSON file can directly uploaded into the Postman client or through their API.
Using the postman schema we can build Postman Collections using python endpoints from Sanic (Flask apps need testing). The script parses the Sanic app. It searches for blueprints. The blueprints, through routes, provide docs strings data. The doc string data is used to populate a Postman formatted JSON file. The JSON file can then be uploaded to Postman as a collection.
Once we have Postman formatted JSON we can create API documentation through the Postman API
How to use
-
run
from sanic_to_json import generate_sanic_json
andgenerate_sanic_json("collection_name", app)
Formats the Postman collection with 'collection_name' and doc strings from Sanic app, e.g.,postman_collection.json
-
to execute an example run
python -m examples.example_script
How to document Sanic app and Blueprints
-
As the example shows, the Sanic app should have a
.doc
attribute. This doc string will serve as the introduction to the API in Postman docs, e.g.,app.__doc__ = "This API does stuff."
-
Blueprints should also a doc string, this will serve as the description to each collection folder in Postman. Again see
examples
folderbp1.__doc__ = "This is the doc string for blueprint1."
How to install
pip install sanic-to-json
To do
- At the moment endpoints are assumed to accept raw JSON, as passed by the header option in
sanic_to_json.atomic_requests
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text",
}
]
Arguments to the header key could be passed in the doc strings, but I'll leave that for a future endevaor.
Contributors
See the GitHub contributor page
License
sanic-to-json is open source software licensed as MIT.
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
Built Distribution
File details
Details for the file sanic-to-json-0.1.5.tar.gz
.
File metadata
- Download URL: sanic-to-json-0.1.5.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.1 Linux/4.15.0-1028-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b909a8c4e4f12186ff75fabcf8331339ef5f2ad756c98c1bb192082b17b35373 |
|
MD5 | 9e5e890a2021ccc4151ea234b33eeb41 |
|
BLAKE2b-256 | e07591e37c05526b9eee6ee84054b9e390db25b5f4191c0fedc2a7d00488004c |
File details
Details for the file sanic_to_json-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: sanic_to_json-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.1 Linux/4.15.0-1028-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 403dc089906bea973b7629511bc69cd15c9bef883454d09d92f0529285a4d99e |
|
MD5 | b04517ec937466fd94d301ca2d38d0d8 |
|
BLAKE2b-256 | c86efec7c09317892470e022ee1b3284575af1d89f7d3426a55b2737949639f5 |