Configurations¶
Sanic-OpenAPI provides following configurable items:
- API Server
- API information
- Authentication(Security Definitions)
- URI filter
- Swagger UI configurations
API Server¶
By default, Swagger will use exactly the same host which served itself as the API server. But you can still override this by setting following configurations. For more information, please check document at here.
API_HOST¶
Key:
API_HOSTType:
strof IP, or hostnameDefault:
NoneUsage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_HOST = "petstore.swagger.io"
Result:

API_BASEPATH¶
Key:
API_BASEPATHType:
strDefault:
NoneUsage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_BASEPATH = "/api"
Result:

API_SCHEMES¶
Key:
API_SCHEMESType:
listof schemesDefault:
["http"]Usage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_SCHEMES = ["https"]
Result:

API information¶
You can provide some additional information of your APIs by using Sanic-OpenAPI configurations. For more detail of those additional information, please check the document from Swagger.
API_VERSION¶
Key:
API_VERSIONType:
strDefault:
1.0.0Usage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_VERSION = "0.1.0"
Result:

API_TITLE¶
Key:
API_TITLEType:
strDefault:
APIUsage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_TITLE = "Sanic-Example-OpenAPI"
Result:

API_DESCRIPTION¶
Key:
API_DESCRIPTIONType:
strDeafult:
""Usage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_DESCRIPTION = "An example Swagger from Sanic-OpenAPI"
Result:

API_TERMS_OF_SERVICE¶
Key:
API_TERMS_OF_SERVICEType:
strof a URLDeafult:
""Usage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_TERMS_OF_SERVICE = "https://github.com/sanic-org/sanic-openapi/blob/master/README.md"
Result:

API_CONTACT_EMAIL¶
Key:
API_CONTACT_EMAILType:
strof email addressDeafult:
None"Usage:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_CONTACT_EMAIL = "foo@bar.com"
Result:

API_LICENSE_NAME¶
Key:
API_LICENSE_NAMEType:
strDefault:
NoneUsage:
python from sanic import Sanic from sanic_openapi import openapi3_blueprint
app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_LICENSE_NAME = “MIT”
Result:

API_LICENSE_URL¶
Key:
API_LICENSE_URLType:
strof URLDefault:
NoneUsgae:
from sanic import Sanic from sanic_openapi import openapi3_blueprint app = Sanic() app.blueprint(openapi3_blueprint) app.config.API_LICENSE_URL = "https://github.com/sanic-org/sanic-openapi/blob/master/LICENSE"
Result:
