Sphinx extension allows you to test json apis
Project description
About
This extension makes it simple to add a widget allowing users to test JSON requests against your api form the documentation. It has support for parameters that get injected into the url path and to post JSON data to the api. It does not have support for query string parameters or form encoded post data (if you would like this, please add it and send a pull request).
There is support for client side json-schema validation (currently only for draft04). jsontest uses tv4 for schema validation. jsontest supports loading schemas from different files provided they can be accessed from the same host either using a relative path (e.g. sample.json) or a full path for the same host (e.g. /schemas/sample.json)
jsontest requires sphinxcontrib.httdomain documented apis and uses the dom to add events to elements on the page (it does expect a specific structure of the dom).
jsontest was designed for use with the readthedocs sphinx theme - it has not been tested with the other themes. If you want to sue the read the docs theme just set the html_theme in your conf.py:
html_theme = 'sphinx_rtd_theme'
Setup
To install (assuming you have pip setup) just run:
pip install sphinxcontrib-jsontest
Then add sphinxcontrib.jsontest to your list of extensions in conf.py:
extensions = ['sphinxcontrib.httpdomain', 'sphinxcontrib.jsontest']
Usage
To add teh test api functionality to an endpoint just add the directive in the block that generates the api endpoint (this is necessary because jsontest relies on a failry specific dom structure):
.. jsontest::
jsontest can’t figure out url args from the description yet, so if you rely on them you have to add them to the url_args option for the directive as a line separated list of key=value pairs (where value is the default value):
.. jsontest:: :url_args: customername=bob orderid=12
If you want to add a textarea for inputting json to the request just add the json_input option (with no argument):
.. jsontest:: :json_input:
And if you want to add a schema check to the json input add the schema option and pass the url or relative path to the schema file to validate against:
.. jsontest:: :json_input: :schema: schemas/test_input.json
You can combine the url_args, json_input and schema options.
License
The code is available as “public domain”, meaning that it is completely free to use, without any restrictions at all. Read the full license here.
It’s also available under an MIT license. MIT license
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
File details
Details for the file sphinxcontrib-jsontest-0.1.5.tar.gz
.
File metadata
- Download URL: sphinxcontrib-jsontest-0.1.5.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc2db36339ca4048ac588cc3d39b4d3760cde317c79851c3d6eb8f3bf711ce18 |
|
MD5 | e7527eabbfc87017d46ce6b347cc5429 |
|
BLAKE2b-256 | 4d67491268d3cc6ed900b17fc9cbe0dd7def5d06864f106dfb43433119364baf |