Skip to main content

swagger doc for tornado

Project description

SwaggerDoc

Python Tornado

About

A swagger tool for tornado, using python to write api doc!

Installation

pip install swagger-doc

Quick Start

code

import tornado.ioloop
import tornado.web

from pydantic import Field
from swagger_doc import setup_swagger, swagger_doc, SResponse200, SResponse401, STag, SObject, SPath, SQuery, SBody


class SwaggerTag(STag):
    home = "home"


class RequestPath(SPath):
    __example__ = {"id": 111}

    id: int = Field(description="id")


class RequestQuery(SQuery):
    __example__ = {"page": 10}

    page: int = Field(description="page")


class RequestBody(SBody):
    __example__ = {"name": "lisi"}

    name: str = Field(description="name")

    
class SuccessResp(SObject):
    __example__ = {"code": "0"}

    code: str = Field(description="response code")


class UnauthorizedResp(SObject):
    __example__ = {"code": 401}


class MainHandler(tornado.web.RequestHandler):
    @swagger_doc(
        tags=[SwaggerTag.home],
        summary="show home page",
        query_params=RequestQuery,
        path_params=RequestPath,
        request_body=RequestBody,
        responses=[SResponse200(body=SuccessResp), SResponse401(body=UnauthorizedResp)],
    )
    def post(self, id_):
        self.write("Hello, world")


class AppWithSwagger(tornado.web.Application):
    def __init__(self, routes, *args, **kwargs):
        setup_swagger(
            routes,
            swagger_url="/docs",
            redoc_url="/redoc",
            openapi_url="/openapi.json",
            description="",
            api_version="1.0.0",
            title="API DOCS.",
        )
        super().__init__(routes, *args, **kwargs)


def make_app():
    return AppWithSwagger([(r"/(\d+)", MainHandler)])


if __name__ == "__main__":
    app = make_app()
    app.listen(8885)
    print(f"docs: http://localhost:8885/docs")
    tornado.ioloop.IOLoop.current().start()

Authroization

default account&password: swagger:swagger
wechaty

Swagger

wechaty

Redoc

wechaty

Examples

see examples

TODO

  1. other response(only support json response currently)
  2. search bar
  3. ...

Project details


Download files

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

Source Distribution

swagger-doc-0.0.10.tar.gz (788.1 kB view details)

Uploaded Source

Built Distribution

swagger_doc-0.0.10-py3-none-any.whl (795.9 kB view details)

Uploaded Python 3

File details

Details for the file swagger-doc-0.0.10.tar.gz.

File metadata

  • Download URL: swagger-doc-0.0.10.tar.gz
  • Upload date:
  • Size: 788.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for swagger-doc-0.0.10.tar.gz
Algorithm Hash digest
SHA256 e014c975ec60e39b6bd891bf1b47e0d6370722347cbdbd18558bee9cefcc5d30
MD5 98f9ea262f0da176aa9609c3024a7c80
BLAKE2b-256 95c9480829cc8e49d6069ed3d69ed676deb6cb7c86afbf83f4fe00fc83bb3f4e

See more details on using hashes here.

File details

Details for the file swagger_doc-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: swagger_doc-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 795.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for swagger_doc-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8bd65fc8c3f85edda7e78175a1901c7d7a748cb74c1b93ba98090cabd7863004
MD5 9d7a29b17eb8c8d3463e8d2e03d650b7
BLAKE2b-256 faa8c2766ada657d4313343630a689806e48ea23d19c3833f63bdd24c1d25e20

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page