hfaran / Tornado-JSON

A simple JSON API framework based on Tornado
http://tornado-json.readthedocs.org/
MIT License
273 stars 60 forks source link

New interface proposal for schema definition #31

Closed hfaran closed 10 years ago

hfaran commented 10 years ago

Rather than using the awkward apid class variable...

from tornado_json import schema

@schema.validate
def post(self):
    """POST the required parameters to rule the world

    * `secret`: The secret to ruling the world 
    """
    __schemas__ = schema.Schema(
        input=input_schema,
        output=output_schema
    )
    __schemas__["input"]["example"] = ...
    __schemas__["output"]["example"] = ...

    # Do some cool stuff here
    # ...
    return world

That is:

hfaran commented 10 years ago

Use inspect.cleandoc to remove whitespace from documentation to preserve formatting for GFM.

hfaran commented 10 years ago

__schemas__ can instead be provided as a keyword-argument. Tornado should probably ignore it; however, can be stripped out if needed by modifying the method in BaseHandler.initialize

hfaran commented 10 years ago

Schemas can actually probably just be decorators, since the documentation is generated on app startup anyways.

@input_schema(schema=..., example=...)
hfaran commented 10 years ago

Resolved by #41