All Projects → SerenaFeng → tornado-swagger

SerenaFeng / tornado-swagger

Licence: MIT License
No description or website provided.

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to tornado-swagger

OpenScraper
An open source webapp for scraping: towards a public service for webscraping
Stars: ✭ 80 (+122.22%)
Mutual labels:  tornado
Fukei
A socks proxy based Tornado
Stars: ✭ 82 (+127.78%)
Mutual labels:  tornado
chat
Chat
Stars: ✭ 12 (-66.67%)
Mutual labels:  tornado
fastapi-auth0
FastAPI authentication and authorization using auth0.com
Stars: ✭ 104 (+188.89%)
Mutual labels:  swagger-ui
facescore
人脸打分服务,通过tensorflow通过人脸识别,测年龄,最终返回打分的json
Stars: ✭ 31 (-13.89%)
Mutual labels:  tornado
fastweb
fastweb is a web-server integration solution. It based on tornado, celery, thrift.
Stars: ✭ 17 (-52.78%)
Mutual labels:  tornado
vim-swagger-preview
A Vim plugin for previewing swagger/openAPI spec in Chrome with swagger-ui.
Stars: ✭ 19 (-47.22%)
Mutual labels:  swagger-ui
greentor
Patch pymysql to support tornado asynchronous
Stars: ✭ 31 (-13.89%)
Mutual labels:  tornado
AzureFunctions.Extensions
This provides some useful extensions for Azure Functions.
Stars: ✭ 81 (+125%)
Mutual labels:  swagger-ui
docs
Bitwarden application and API documentation.
Stars: ✭ 66 (+83.33%)
Mutual labels:  swagger-ui
swagger-more
Dubbo Swagger, 自动化DUBBO API文档 (扩展springfox swagger2)
Stars: ✭ 51 (+41.67%)
Mutual labels:  swagger-ui
CleanArchitecture-Template
This is a solution template for Clean Architecture and CQRS implementation with ASP.NET Core.
Stars: ✭ 60 (+66.67%)
Mutual labels:  swagger-ui
memoize
Caching library for asynchronous Python applications.
Stars: ✭ 53 (+47.22%)
Mutual labels:  tornado
instant api
Instantly create an HTTP API with automatic type conversions, JSON RPC, and a Swagger UI. Just add methods!
Stars: ✭ 115 (+219.44%)
Mutual labels:  swagger-ui
asymmetric
Ridiculously fast and easy module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.
Stars: ✭ 35 (-2.78%)
Mutual labels:  swagger-ui
factory
Docker microservice & Crawler by scrapy
Stars: ✭ 56 (+55.56%)
Mutual labels:  tornado
crud
Swagger/OpenAPI builder and input validation for Go APIs
Stars: ✭ 34 (-5.56%)
Mutual labels:  swagger-ui
apiflask
A lightweight Python web API framework.
Stars: ✭ 442 (+1127.78%)
Mutual labels:  swagger-ui
aws-swaggerui
Serverless Swagger UI for API Gateway
Stars: ✭ 26 (-27.78%)
Mutual labels:  swagger-ui
webTimer
一款时间管理小工具的chrome插件
Stars: ✭ 18 (-50%)
Mutual labels:  tornado

tornado-swagger

What is tornado-swagger?

tornado is a wrapper for tornado which enables swagger-ui support.

In essense, you just need to wrap the Api instance and add a few python decorators to get full swagger support.

How to:

Install:

pip install .

(This installs tornado and epydoc as well)

And in your program, where you'd usually just use tornado, add just a little bit of sauce and get a swagger spec out.

from tornado.web import RequestHandler, HTTPError
from tornado_swagger import swagger

swagger.docs()

# You may decorate your operation with @swagger.operation and use docs to inform information
class ItemNoParamHandler(GenericApiHandler):
    @swagger.operation(nickname='create')
    def post(self):
        """
            @param body: create test results for a item.
            @type body: L{Item}
            @return 200: item is created.
            @raise 400: invalid input
        """

# Operations not decorated with @swagger.operation do not get added to the swagger docs

class ItemNoParamHandler(GenericApiHandler):
    def options(self):
        """
        I'm not visible in the swagger docs
        """
        pass


# Then you use swagger.Application instead of tornado.web.Application
# and do other operations as usual

def make_app():
    return swagger.Application([
        (r"/items", ItemNoParamHandler),
        (r"/items/([^/]+)", ItemHandler),
        (r"/items/([^/]+)/cases/([^/]+)", ItemOptionParamHandler),
    ])

# You define models like this:
@swagger.model
class Item:
    """
        @descriptin:
            This is an example of a model class that has parameters in its constructor
            and the fields in the swagger spec are derived from the parameters to __init__.
        @notes:
            In this case we would have property1, property2 as required parameters and property3 as optional parameter.
        @property property3: Item decription
        @ptype property3: L{PropertySubclass}
    """
    def __init__(self, property1, property2=None):
        self.property1 = property1
        self.property2 = property2

# Swagger json:
    "models": {
        "Item": {
            "description": "A description...",
            "id": "Item",
            "required": [
                "property1",
            ],
            "properties": [
                "property1": {
                    "type": "string"
                },
                "property2": {
                    "type": "string"
                    "default": null
                }
            ]
        }
    }

# If you declare an __init__ method with meaningful arguments
# then those args could be used to deduce the swagger model fields.
# just as shown above

# if you declare an @property in docs, this property property2 will also be used to deduce the swagger model fields
class Item:
    """
        @property property3: Item description
    """
    def __init__(self, property1, property2):
        self.property1 = property1
        self.property2 = property2

# Swagger json:
    "models": {
        "Item": {
            "description": "A description...",
            "id": "Item",
            "required": [
                "property1",
            ],
            "properties": [
                "property1": {
                    "type": "string"
                },
                "property2": {
                    "type": "string"
                }
                "property3": {
                    "type": "string"
                }
            ]
        }
    }

# if you declare an argument with @ptype, the type of this argument will be specified rather than the default 'string'
class Item:
    """
        @ptype property3: L{PropertySubclass}
    """
    def __init__(self, property1, property2, property3=None):
        self.property1 = property1
        self.property2 = property2
        self.property3 = property3

# Swagger json:
    "models": {
        "Item": {
            "description": "A description...",
            "id": "Item",
            "required": [
                "property1",
            ],
            "properties": [
                "property1": {
                    "type": "string"
                },
                "property2": {
                    "type": "string"
                },
                "property3": {
                    "type": "PropertySubclass"
                    "default": null
                }
            ]
        }
    }

# if you want to declare an list property, you can do it like this:
class Item:
    """
        @ptype property3: L{PropertySubclass}
        @ptype property4: C{list} of L{PropertySubclass}
    """
    def __init__(self, property1, property2, property3, property4=None):
        self.property1 = property1
        self.property2 = property2
        self.property3 = property3
        self.property4 = property4

# Swagger json:
    "models": {
        "Item": {
            "description": "A description...",
            "id": "Item",
            "required": [
                "property1",
            ],
            "properties": [
                "property1": {
                    "type": "string"
                },
                "property2": {
                    "type": "string"
                },
                "property3": {
                    "type": "PropertySubclass"
                    "default": null
                },
                "property4": {
                    "default": null,
                    "items": {
                        "type": "PropertySubclass"},
                        "type": "array"
                    }
                }
            ]
        }
    }

Running and testing

Now run your tornado app

python basic.py

And visit:

curl http://localhost:7111/swagger/spec

access to web

http://localhost:7111/swagger/spec.html

Passing more metadata to swagger

customized arguments used in creating the 'swagger.docs' object will be supported later

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].