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-0.0.12.tar.gz
(790.5 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
swagger_doc-0.0.12-py3-none-any.whl
(792.2 kB
view details)
File details
Details for the file swagger_doc-0.0.12.tar.gz.
File metadata
- Download URL: swagger_doc-0.0.12.tar.gz
- Upload date:
- Size: 790.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12cf81556949004c420b14bf463a61decfed2a9b7c9f9a8879c3a01da0b8c783
|
|
| MD5 |
d454962d2f798190d4a0e7cc3c83b949
|
|
| BLAKE2b-256 |
c11b5e1fe00a7d883fba7142d7f919987f7df67ff8bb435d8b01196de77c01fd
|
File details
Details for the file swagger_doc-0.0.12-py3-none-any.whl.
File metadata
- Download URL: swagger_doc-0.0.12-py3-none-any.whl
- Upload date:
- Size: 792.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6b177267af7a7243dc7e9e62b58fee4a313ccc7e35232c968654cc17cfafe68
|
|
| MD5 |
725771a21b383a38cf89b9d5296ada90
|
|
| BLAKE2b-256 |
2f3304596bda52d189653d6b26a5db9a8db4879cadce872d53e82a15f003d785
|