Create 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
generate_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.3.tar.gz
.
File metadata
- Download URL: sanic-to-json-0.1.3.tar.gz
- Upload date:
- Size: 4.7 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 | e76210d59308c6f90a1252973e05860a6c496778397ac93c5e0754507b4ed75b |
|
MD5 | 4f2cfc3603ab6d335e9ff94fc4765069 |
|
BLAKE2b-256 | d8ebe345ebcfacfbe2bc9422908fec0706ae2fb91e6e935b80562aac04ab3c2f |
File details
Details for the file sanic_to_json-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: sanic_to_json-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.9 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 | 3084103b0a3d0eb65fe84cb256322d2d923d5b8ed8b9ae6f1756a6d862ac410a |
|
MD5 | 283d1faab7926c18a40c79735a5b3a11 |
|
BLAKE2b-256 | de1ee6b7d2f24ca50d82ed77283ef57b7a43c6d7423c4472228dba48483c97a3 |