Skip to main content

RESTiro

Build Status Coverage Status

RESTful API documentation generator (inline documentation + tests)

Features

  • Inline documentation parser
  • Example recorder middleware
  • Generate documentation in Markdown
  • Generate documentation in HTML [restiro-spa-material]

Install

    pip install restiro

Usage

  1. Describe the request in comments, e.g:

    controller/shelf.py

    class ShelfController:
        
        def post(self):
            """
            @api {post} /shelf/:shelfId/book Add book into shelf
    
            @apiVersion 1
            @apiGroup Book
            @apiPermission Noneres
            
            @apiParam {String} title
            @apiParam {String} author
            @apiParam {DateTime} [publishDate]
             
            @apiDescription 
            Here is some description
            with full support of markdown.
            
            - watch this!
            - and this!
            - there is a list!
            """
            return [11, 22, 33]
    
  2. Attach restiro middleware to your WSGI/HTTP verifier (currently webtest supported), e.g:

    Your project tests initializer:

    from restiro.middlewares.webtest import TestApp
    from restiro import clean_examples_dir
    
    from my_project import wsgi_app
    
    clean_examples_dir()
    test_app = TestApp(wsgi_app)
    
  3. Define responses to capture, e.g:

    def test_shelf(test_app):
        test_app.get('/shelf/100/book')
        
        test_app.delete('/shelf/121/book')
        
        test_app.doc = True
        test_app.post(
            '/shelf/100/book',
            json={
                'title': 'Harry Potter',
                'author': 'JK. Rowling'
            }
        )
        
        test_app.doc = True
        test_app.post(
            '/shelf/100/book',
            json={
                'title': 'Harry Potter2'
            },
            status=400
        )
    
  4. Run tests

  5. Build documentation

    $ restiro a_library
    

    Response will be something like:

    shelf-{shelf_id}-book-post.md

        #  Add book into shelf
        
        ## `POST` `/shelf/:shelfId/book`
        
        Here is some description
        with full support of markdown.
        
        - watch this!
        - and this!
        - there is a list!
        
        
        ## Parameters
        
        ### Form parameters
        
        Name | Type | Required | Default | Example | enum | Pattern | MinLength | MaxLength | Minimum | Maximum | Repeat | Description
        --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
        title | String | `True` |  |  |  |  |  |  |  |  | `False` | 
        author | String | `True` |  |  |  |  |  |  |  |  | `False` | 
        publishDate | DateTime | `False` |  |  |  |  |  |  |  |  | `False` | 
        
        ## Examples
        
        ### 200 OK
        
        #### Request: 
        
        ```
        POST /shelf/100/book
        Content-Type: application/x-www-form-urlencoded
        ```
        ```
        title=Harry Potter
        author=JK. Rowling
        ```
        
        #### Response: 
        
        ```
        Content-Type: application/json
        ```
        ```
        [11, 22, 33]
        ```
        
        
        ### 400 Bad Request, missed parameter `author`
        
        #### Request: 
        
        ```
        POST /shelf/100/book
        Content-Type: application/x-www-form-urlencoded
        ```
        ```
        title=Harry Potter2
        ```
        
        #### Response: 
        
        ```
        Content-Type: application/json
        ```
        ```
        {"message": "Missed parameter `author`"}
        ```
        
        ---
    

CLI

usage: restiro [-h] [-t TITLE] [-o OUTPUT] [-b BASE_URI]
               [-g {markdown,json,spa_material,mock}] [-l LOCALES]
               [--build-gettext [BUILD_GETTEXT]]
               src

Restiro Builder

positional arguments:
  src                   Project module name

optional arguments:
  -h, --help            show this help message and exit
  -t TITLE, --title TITLE
                        Project title
  -o OUTPUT, --output OUTPUT
                        Output directory
  -b BASE_URI, --base-uri BASE_URI
                        Base URI
  -g {markdown,json,spa_material,mock}, --generator {markdown,json,spa_material,mock}
                        Generator, default: markdown
  -l LOCALES, --locales LOCALES
                        Locales directory
  --build-gettext [BUILD_GETTEXT]
                        Build .POT templates

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

restiro-0.19.1.tar.gz (20.5 kB view details)

Uploaded Source

File details

Details for the file restiro-0.19.1.tar.gz.

File metadata

  • Download URL: restiro-0.19.1.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7

File hashes

Hashes for restiro-0.19.1.tar.gz
Algorithm Hash digest
SHA256 fb9b7083fc0b5aff83abfe5a59015c4cddd9762c2e94d34dbddc569aa971f2a3
MD5 81607b69955a3be0e479cf15bd00d790
BLAKE2b-256 2967d38869a30917fd80a875fc04de8aea30e45349a67d1c8db66fc22cef2955

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.19.1 This release

1 file

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

1 file

0.11.0

1 file

0.10.0

1 file

0.9.1

1 file

0.9.0

1 file

0.8.0

1 file

0.7.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page