Code
Using the local config file
from swagger_ui import api_doc
api_doc(app, config_path='./config/test.yaml', url_prefix='/api/doc', title='API doc')
Or using config url, but need to suport CORS
api_doc(app, config_url='https://petstore.swagger.io/v2/swagger.json', url_prefix='/api/doc', title='API doc')
Or using the config spec string
from swagger_ui import api_doc
spec_string = '{"openapi":"3.0.1","info":{"title":"python-swagger-ui test api","description":"python-swagger-ui test api","version":"1.0.0"},"servers":[{"url":"http://127.0.0.1:8989/api"}],"tags":[{"name":"default","description":"default tag"}],"paths":{"/hello/world":{"get":{"tags":["default"],"summary":"output hello world.","responses":{"200":{"description":"OK","content":{"application/text":{"schema":{"type":"object","example":"Hello World!!!"}}}}}}}},"components":{}}'
api_doc(app, config_spec=spec_string, url_prefix='/api/doc', title='API doc')
Or using the config dict
from swagger_ui import api_doc
config = {"openapi":"3.0.1","info":{"title":"python-swagger-ui test api","description":"python-swagger-ui test api","version":"1.0.0"},"servers":[{"url":"http://127.0.0.1:8989/api"}],"tags":[{"name":"default","description":"default tag"}],"paths":{"/hello/world":{"get":{"tags":["default"],"summary":"output hello world.","responses":{"200":{"description":"OK","content":{"application/text":{"schema":{"type":"object","example":"Hello World!!!"}}}}}}}},"components":{}}
api_doc(app, config=config, url_prefix='/api/doc', title='API doc')
And suport config file with editor
api_doc(app, config_path='./config/test.yaml', editor=True)
And keep the old way
from swagger_ui import tornado_api_doc
tornado_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
from swagger_ui import sanic_api_doc
sanic_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
from swagger_ui import flask_api_doc
flask_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
from swagger_ui import quart_api_doc
quart_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
from swagger_ui import aiohttp_api_doc
aiohttp_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
from swagger_ui import falcon_api_doc
falcon_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
Passing a value to the keyword argument host_inject
will disable the behaviour which injects a host value into the specification served by Swagger UI.