# Basic Authentication Samplebasic={"type":"http","scheme":"basic"}# JWT Bearer Samplejwt={"type":"http","scheme":"bearer","bearerFormat":"JWT"}# API Key Sampleapi_key={"type":"apiKey","name":"api_key","in":"header"}# Implicit OAuth2 Sampleoauth2={"type":"oauth2","flows":{"implicit":{"authorizationUrl":"https://example.com/api/oauth/dialog","scopes":{"write:pets":"modify pets in your account","read:pets":"read your pets"}}}}security_schemes={"jwt":jwt,"api_key":api_key,"oauth2":oauth2,"basic":basic}
First, you need to define the security_schemes and security variable:
An array of Server Objects, which provide connectivity information to a target server. If the server's property is not
provided, or is an empty array, the default value would be a Server Object with an url value of /.
fromstar_openapiimportOpenAPI,ExternalDocumentationexternal_docs=ExternalDocumentation(url="https://www.openapis.org/",description="Something great got better, get excited!")app=OpenAPI(info=info,external_docs=external_docs)
While the OpenAPI Specification tries to accommodate most use cases,
additional data can be added to extend the specification at certain points.
See Specification Extensions.
It can also be available in every api, goto Operation.
You can override validation error response use validation_error_status, validation_error_model
and validation_error_callback.
validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic.
Defaults to 422.
validation_error_model: Validation error response model for OpenAPI Specification.
validation_error_callback: Validation error response callback, the return format corresponds to
the validation_error_model. Receive ValidationError and return Starlette Response.