swagger doc for tornado
Project description
SwaggerDoc
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
Swagger
Redoc
Examples
see examples
TODO
- other response(only support json response currently)
- search bar
- ...
Project details
Release history Release notifications | RSS feed
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_v2-0.0.3.tar.gz
(791.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swagger_doc_v2-0.0.3.tar.gz.
File metadata
- Download URL: swagger_doc_v2-0.0.3.tar.gz
- Upload date:
- Size: 791.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc240137c9b75a0418eaa88de44a97c67553bd5d5ad7f4ec1edf557dc457d95b
|
|
| MD5 |
d9ece19f72bfc9b4000634ecc4517fcd
|
|
| BLAKE2b-256 |
8e2abdba8149e982d84bff7da113572ed132ab7f82a5c69ccf8d55f95e41d5af
|
File details
Details for the file swagger_doc_v2-0.0.3-py3-none-any.whl.
File metadata
- Download URL: swagger_doc_v2-0.0.3-py3-none-any.whl
- Upload date:
- Size: 796.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
596ca6e2c504577db216f842336ab43fe20c6e9d8bf9bea59a7303b9a0d82d77
|
|
| MD5 |
e6b12f7b5e0227af7abb6174c949e88f
|
|
| BLAKE2b-256 |
e28aef7d076451a52062e7c9423f26404c88b2441e2942bfda38ae1018ed5935
|