Metadata-Version: 2.1
Name: sanic-to-json
Version: 0.1.3
Summary: Create JSON API documentation files from Sanic 
Home-page: https://github.com/kountable/sanic-to-json
License: MIT
Author: Cristian Heredia
Author-email: cheredia@kountable.com
Requires-Python: >=3.7,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Requires-Dist: sanic (>=19.6,<20.0)
Project-URL: Repository, https://github.com/kountable/sanic-to-json
Description-Content-Type: text/markdown

<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>

[![Build Status](https://travis-ci.org/kountable/sanic-to-json.svg?branch=master)](https://travis-ci.org/kountable/sanic-to-json)

# sanic-to-json
Generate a Postman [JSON](http://json.org) file from a [Sanic app](https://sanic.readthedocs.io/en/latest/index.html#). The JSON file can directly uploaded into the [Postman client](https://www.getpostman.com) or through their [API](https://docs.api.getpostman.com/?version=latest#3190c896-4216-a0a3-aa38-a041d0c2eb72).  

Using the postman [schema](https://schema.getpostman.com/json/collection/v2.1.0/collection.json) 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](https://docs.api.getpostman.com/?version=latest#3190c896-4216-a0a3-aa38-a041d0c2eb72)

## 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` folder
`bp1.__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](https://github.com/kountable/sanic-to-json/graphs/contributors)


## License
sanic-to-json is open source software [licensed as MIT](https://github.com/kountable/sanic-to-json/blob/master/LICENSE).
