项目作者: meyt

项目描述 :
RESTful API documentation generator (inline documentation + tests)
高级语言: Python
项目地址: git://github.com/meyt/restiro.git
创建时间: 2017-07-01T18:23:55Z
项目社区:https://github.com/meyt/restiro

开源协议:MIT License

下载


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

  1. pip install restiro

Usage

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

    controller/shelf.py

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

    Your project tests initializer:

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

    1. def test_shelf(test_app):
    2. test_app.get('/shelf/100/book')
    3. test_app.delete('/shelf/121/book')
    4. test_app.doc = True
    5. test_app.post(
    6. '/shelf/100/book',
    7. json={
    8. 'title': 'Harry Potter',
    9. 'author': 'JK. Rowling'
    10. }
    11. )
    12. test_app.doc = True
    13. test_app.post(
    14. '/shelf/100/book',
    15. json={
    16. 'title': 'Harry Potter2'
    17. },
    18. status=400
    19. )
  3. Run tests

  4. Build documentation

    1. $ restiro a_library

    Response will be something like:

    shelf-{shelf_id}-book-post.md
    ```markdown

    1. # Add book into shelf
    2. ## `POST` `/shelf/:shelfId/book`
    3. Here is some description
    4. with full support of markdown.
    5. - watch this!
    6. - and this!
    7. - there is a list!
  1. ## Parameters
  2. ### Form parameters
  3. Name | Type | Required | Default | Example | enum | Pattern | MinLength | MaxLength | Minimum | Maximum | Repeat | Description
  4. --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
  5. title | String | `True` | | | | | | | | | `False` |
  6. author | String | `True` | | | | | | | | | `False` |
  7. publishDate | DateTime | `False` | | | | | | | | | `False` |
  8. ## Examples
  9. ### 200 OK
  10. #### Request:
  11. ```
  12. POST /shelf/100/book
  13. Content-Type: application/x-www-form-urlencoded
  14. ```
  15. ```
  16. title=Harry Potter
  17. author=JK. Rowling
  18. ```
  19. #### Response:
  20. ```
  21. Content-Type: application/json
  22. ```
  23. ```
  24. [11, 22, 33]
  25. ```
  26. ### 400 Bad Request, missed parameter `author`
  27. #### Request:
  28. ```
  29. POST /shelf/100/book
  30. Content-Type: application/x-www-form-urlencoded
  31. ```
  32. ```
  33. title=Harry Potter2
  34. ```
  35. #### Response:
  36. ```
  37. Content-Type: application/json
  38. ```
  39. ```
  40. {"message": "Missed parameter `author`"}
  41. ```
  42. ---
  43. ```

CLI

  1. usage: restiro [-h] [-t TITLE] [-o OUTPUT] [-b BASE_URI]
  2. [-g {markdown,json,spa_material,mock}] [-l LOCALES]
  3. [--build-gettext [BUILD_GETTEXT]]
  4. src
  5. Restiro Builder
  6. positional arguments:
  7. src Project module name
  8. optional arguments:
  9. -h, --help show this help message and exit
  10. -t TITLE, --title TITLE
  11. Project title
  12. -o OUTPUT, --output OUTPUT
  13. Output directory
  14. -b BASE_URI, --base-uri BASE_URI
  15. Base URI
  16. -g {markdown,json,spa_material,mock}, --generator {markdown,json,spa_material,mock}
  17. Generator, default: markdown
  18. -l LOCALES, --locales LOCALES
  19. Locales directory
  20. --build-gettext [BUILD_GETTEXT]
  21. Build .POT templates