Skip to content

Commit

Permalink
Merge pull request #54 from hfaran/develop
Browse files Browse the repository at this point in the history
develop -> master
  • Loading branch information
hfaran committed Dec 9, 2014
2 parents e592b45 + 9c4b8d0 commit fdb532e
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 92 deletions.
36 changes: 28 additions & 8 deletions demos/helloworld/API_Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
Content-Type: application/json

## GET


**Input Schema**
```json
null
```



**Output Schema**
```json
{
"type": "string"
}
```


**Output Example**
```json
"Hello (asynchronous) world!"
Expand Down Expand Up @@ -48,18 +53,23 @@ Shouts hello to the world (asynchronously)!
Content-Type: application/json

## GET


**Input Schema**
```json
null
```



**Output Schema**
```json
{
"type": "string"
}
```


**Output Example**
```json
"Greetings, Named Person!"
Expand All @@ -80,18 +90,23 @@ Greets you.
Content-Type: application/json

## GET


**Input Schema**
```json
null
```



**Output Schema**
```json
{
"type": "string"
}
```


**Output Example**
```json
"Hello world!"
Expand All @@ -112,45 +127,50 @@ Shouts hello to the world!
Content-Type: application/json

## POST


**Input Schema**
```json
{
"type": "object",
"properties": {
"body": {
"type": "string"
},
},
"index": {
"type": "number"
},
},
"title": {
"type": "string"
}
}
},
"type": "object"
}
```


**Input Example**
```json
{
"body": "Equally important message",
"index": 0,
"body": "Equally important message",
"index": 0,
"title": "Very Important Post-It Note"
}
```


**Output Schema**
```json
{
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
},
"type": "object"
}
```


**Output Example**
```json
{
Expand Down
7 changes: 4 additions & 3 deletions tests/func_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from tornado.testing import AsyncHTTPTestCase

from .utils import handle_import_error

try:
sys.path.append('.')
from tornado_json import routes
Expand All @@ -11,9 +13,8 @@
from tornado_json import requesthandlers
sys.path.append('demos/helloworld')
import helloworld
except ImportError as e:
print("Please run `py.test` from the root project directory")
exit(1)
except ImportError as err:
handle_import_error(err)


def jd(obj):
Expand Down
190 changes: 190 additions & 0 deletions tests/helloworld_API_documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
**This documentation is automatically generated.**

**Output schemas only represent `data` and not the full output; see output examples and the JSend specification.**

# /api/asynchelloworld/?

Content-Type: application/json

## GET


**Input Schema**
```json
null
```



**Output Schema**
```json
{
"type": "string"
}
```


**Output Example**
```json
"Hello (asynchronous) world!"
```


**Notes**

Shouts hello to the world (asynchronously)!



<br>
<br>

# /api/freewilled/?

Content-Type: application/json



<br>
<br>

# /api/greeting/\(?P\<fname\>\[a\-zA\-Z0\-9\_\]\+\)/\(?P\<lname\>\[a\-zA\-Z0\-9\_\]\+\)/?$

Content-Type: application/json

## GET


**Input Schema**
```json
null
```



**Output Schema**
```json
{
"type": "string"
}
```


**Output Example**
```json
"Greetings, Named Person!"
```


**Notes**

Greets you.



<br>
<br>

# /api/helloworld/?

Content-Type: application/json

## GET


**Input Schema**
```json
null
```



**Output Schema**
```json
{
"type": "string"
}
```


**Output Example**
```json
"Hello world!"
```


**Notes**

Shouts hello to the world!



<br>
<br>

# /api/postit/?

Content-Type: application/json

## POST


**Input Schema**
```json
{
"properties": {
"body": {
"type": "string"
},
"index": {
"type": "number"
},
"title": {
"type": "string"
}
},
"type": "object"
}
```


**Input Example**
```json
{
"body": "Equally important message",
"index": 0,
"title": "Very Important Post-It Note"
}
```


**Output Schema**
```json
{
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
```


**Output Example**
```json
{
"message": "Very Important Post-It Note was posted."
}
```


**Notes**

POST the required parameters to post a Post-It note

* `title`: Title of the note
* `body`: Body of the note
* `index`: An easy index with which to find the note


21 changes: 18 additions & 3 deletions tests/test_api_doc_gen.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import sys
import os

import pytest
from tornado.web import URLSpec

from .utils import handle_import_error

try:
sys.path.append('.')
from tornado_json.api_doc_gen import _get_tuple_from_route
except ImportError as e:
print("Please run `sudo tox` from the root project directory")
exit(1)
from tornado_json.api_doc_gen import get_api_docs
from tornado_json.routes import get_routes
sys.path.append("demos/helloworld")
import helloworld
except ImportError as err:
handle_import_error(err)


def test__get_tuple_from_route():
Expand All @@ -29,3 +35,12 @@ def test__get_tuple_from_route():
# Test malformed tuple (i.e., smaller length than 2)
with pytest.raises(AssertionError):
_get_tuple_from_route(("foobar",))



def test__get_api_docs():
relative_dir = os.path.abspath(os.path.dirname(__file__))
filepath = os.path.join(relative_dir, "helloworld_API_documentation.md")
HELLOWORLD_DOC = open(filepath).read()

assert get_api_docs(get_routes(helloworld)) == HELLOWORLD_DOC

0 comments on commit fdb532e

Please sign in to comment.