Specification
Specification⚓︎
If you need the complete Specification, go to http://127.0.0.1:5000/openapi/openapi.json
command: flask openapi⚓︎
New in v2.0.0
The flask openapi
command will export the OpenAPI Specification to console when you execute the command.
1 |
|
IMPORT
is the Flask application, in our case an OpenAPI application, to loan.
For example, if your OpenAPI application is app
defined in hello.py
,
as in the example in Quickstart, the command is
flask --app hello:app openapi
.
(For more information about the command line interface of Flask, please check out
the Flask CLI documentation.)
Execute flask --app IMPORT openapi --help
for more information about the command:
Again, assuming your OpenAPI application is app
defined in hello.py
,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Please note, by default, the command will export the OpenAPI specification in JSON.
If you want the OpenAPI specification in YAML, by running the command with the -f yaml
option,
you need to install the pyyaml
package.
1 2 3 4 |
|
info⚓︎
flask-openapi3
provide Swagger UI, Redoc and RapiDoc interactive documentation.
Before that, you should know something about the OpenAPI Specification.
You must import Info
from flask-openapi3
, it needs some parameters: title
, version
... , more information sees the OpenAPI Specification Info Object.
1 2 3 4 5 6 7 8 9 |
|
run it, and go to http://127.0.0.1:5000/openapi, you will see the documentation.
security_schemes⚓︎
There are some examples for Security Scheme Object, more features see the OpenAPI Specification Security Scheme Object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
First, you need to define the security_schemes and security variable:
1 2 3 4 5 6 7 8 9 10 |
|
Second, add pass the security to your api, like this:
1 2 3 |
|
result:
oauth_config⚓︎
New in v0.9.4
You can pass oauth_config
when initializing OpenAPI
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
Here's more information about OAuth 2.0 configuration
responses⚓︎
New in v0.9.4
You can add responses
for each API under the app
wrapper.
1 2 3 4 5 6 7 8 9 |
|
abp_responses & view_responses⚓︎
New in v0.9.4
You can add responses
for each API under the api
or api_view
wrapper.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
You can also use responses and extra_responses in your api.
New in v2.4.0
Deprecated-warning
extra_responses
have been merged into the responses
, and extra_responses
will be deprecated in v3.x.
doc_ui⚓︎
You can pass doc_ui=False
to disable the OpenAPI spec
when init OpenAPI
.
1 |
|
New in v0.9.4
You can also use doc_ui
in endpoint or when initializing APIBlueprint
or APIView
.
1 2 3 4 5 6 7 8 9 10 11 |
|
doc_expansion⚓︎
Just for Swagger UI.
String=["list", "full", "none"].
Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), full' (expands the tags and operations) or 'none' (expands nothing).
More information to see Configuration.
1 |
|
Interactive documentation⚓︎
Flask OpenAPI3 provides support for the following Interactive documentation:
The following are the default values of these configurations. Of course, you can change them:
- doc_prefix = "/openapi"
- api_doc_url = "/openapi.json"
- swagger_url= "/swagger"
- redoc_url = "/redoc"
- rapidoc_url = "/rapidoc"
servers⚓︎
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 /.
1 2 3 4 5 6 7 |
|
external_docs⚓︎
Allows referencing an external resource for extended documentation.
More information to see External Documentation Object.
1 2 3 4 5 6 7 |
|
openapi_extensions⚓︎
new in v2.4.0
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 APIBlueprint and APIView, goto Operation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
validation error⚓︎
new in v2.5.0
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 returnFlask Response
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|