Applying the OpenAPI 3.x specification
The OpenAPI 3.0 specification is a standard API documentation and language-agnostic specification that can describe the API services without knowing its sources, reading its documentation, and understanding its business logic. Additionally, FastAPI supports OpenAPI, and it can even automatically generate the default internal documentation of the API based on OpenAPI standards.
There are three ways to document our API services using the specification:
- By extending the OpenAPI schema definition
- By using the internal code base properties
- By using the
Query
,Body
,Form
, andPath
functions
Extending the OpenAPI schema definition
FastAPI has a get_openapi()
method from its fastapi.openapi.utils
extension that can override some schema descriptions. We can modify the info
, servers
, and paths
details of the schema definition through the get_openapi()
function. The function returns a dict
of all details of the OpenAPI schema...