Specification
Specification⚓︎
If you need the complete Specification, go to http://127.0.0.1:5000/openapi/openapi.json
command: flask openapi⚓︎
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 |
|
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:
responses⚓︎
You can add responses
for each API under the app
wrapper.
1 2 3 4 5 6 7 8 9 |
|
abp_responses & view_responses⚓︎
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 |
|
doc_ui⚓︎
You can pass doc_ui=False
to disable the OpenAPI spec
when init OpenAPI
.
1 |
|
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 |
|
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⚓︎
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⚓︎
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 |
|