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.2.tar.gz
.
File metadata
- Download URL: sanic-to-json-0.1.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.16 CPython/3.7.3 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a893a8ec19742f44e4d86945b8539741c8b8e0ae3f51bacc296663ec5c8d18c |
|
MD5 | 78f194df9bf4137459b2e92ed1240bb5 |
|
BLAKE2b-256 | 94aa9eee0a29384594d8e91521498fafc4cad0749563601562f3d12bb5b04b92 |
File details
Details for the file sanic_to_json-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: sanic_to_json-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.16 CPython/3.7.3 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d92eee16d87e41a589089ed181e229b63f5757090c328219d96a8034943c67cf |
|
MD5 | 1d4ee04aee5815fa5bee28d9a7c404fe |
|
BLAKE2b-256 | 5bbc87fa75977364775832b600bdceff6e7397f768d813b1127e08e4c2f42236 |