Add openapi docs to flask app using Flask-Pydantic
Project description
Flask-Pydantic-Docs
Installation
python3 -m pip install Flask-Pydantic-Docs
Usage
Example
# necessary imports
app = Flask(__name___)
openapi = OpenAPI()
access_denied = APIError(code=403, msg="Access Denied")
@app.route("/post", methods=["POST"])
@openapi_docs(response=ResponseModel, tags=["demo"], exceptions=[access_denied])
@validate()
def post(body: BodyModel, query: QueryModel):
return ResponseModel(
id=id_,
age=query.age,
name=body.name,
nickname=body.nickname,
)
...
openapi.register(app)
NOTE:
-
Since the
openapi_docsdecorator is to register the schemas based on the models used by the view function, so the models have to be put in the view function arguments with annotations as shown in the above example. Otherwise, the schemas cannot be captured. -
The statement
openapi.registerneeds to be run after all view functions orregister_blueprint.
Add Auth Security Schemes
# necessary imports, app and model definition
openapi = OpenAPI(
extra_props={
"components": {
"securitySchemes": {
"bearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
}
}
},
"security": [{"bearerAuth": []}]
},
)
...
openapi.register(app)
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
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 Flask-Pydantic-Docs-0.0.15.tar.gz.
File metadata
- Download URL: Flask-Pydantic-Docs-0.0.15.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13a597cf8a5208f9f307758fd63746cf19f20094afb8028050fe57e9feb0a832
|
|
| MD5 |
78d20b3b95f86437bfdc11268cc06d4e
|
|
| BLAKE2b-256 |
210415c4534f90d87d32f577efd4aa50fa13c458b62917436b4622a786c57fa9
|
File details
Details for the file Flask_Pydantic_Docs-0.0.15-py3-none-any.whl.
File metadata
- Download URL: Flask_Pydantic_Docs-0.0.15-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d6706d3aba06a6fcf8c30572e67e28cd2e7e8293434dba61b7cb84714f86636
|
|
| MD5 |
6fbbdd652eadfd52a0bffcc3753c6aac
|
|
| BLAKE2b-256 |
f70269482f8667082cd9df0c58e27f34d32f498c2f7b6ad973692fbe00da126f
|