get_openapi() — fastapi Function Reference
Architecture documentation for the get_openapi() function in utils.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD d8a9ec8b_6a53_c575_f568_9201405b8883["get_openapi()"] 0dcb823f_ea0d_bd04_752b_a3a3f875bba1["utils.py"] d8a9ec8b_6a53_c575_f568_9201405b8883 -->|defined in| 0dcb823f_ea0d_bd04_752b_a3a3f875bba1 ffc9e3ea_f311_f904_eff9_58c2ce418c50["custom_openapi()"] ffc9e3ea_f311_f904_eff9_58c2ce418c50 -->|calls| d8a9ec8b_6a53_c575_f568_9201405b8883 a9c07abb_aad1_48b4_2dbe_359121a449b2["openapi()"] a9c07abb_aad1_48b4_2dbe_359121a449b2 -->|calls| d8a9ec8b_6a53_c575_f568_9201405b8883 ca85dbd8_2c4a_3a15_71e8_da853c7f62ce["get_fields_from_routes()"] d8a9ec8b_6a53_c575_f568_9201405b8883 -->|calls| ca85dbd8_2c4a_3a15_71e8_da853c7f62ce 200f313e_38b9_296f_f9aa_afdeacb6b8ad["get_openapi_path()"] d8a9ec8b_6a53_c575_f568_9201405b8883 -->|calls| 200f313e_38b9_296f_f9aa_afdeacb6b8ad 1ac1bc37_1a47_e7e2_9156_ab0473094700["jsonable_encoder()"] d8a9ec8b_6a53_c575_f568_9201405b8883 -->|calls| 1ac1bc37_1a47_e7e2_9156_ab0473094700 style d8a9ec8b_6a53_c575_f568_9201405b8883 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/openapi/utils.py lines 480–572
def get_openapi(
*,
title: str,
version: str,
openapi_version: str = "3.1.0",
summary: Optional[str] = None,
description: Optional[str] = None,
routes: Sequence[BaseRoute],
webhooks: Optional[Sequence[BaseRoute]] = None,
tags: Optional[list[dict[str, Any]]] = None,
servers: Optional[list[dict[str, Union[str, Any]]]] = None,
terms_of_service: Optional[str] = None,
contact: Optional[dict[str, Union[str, Any]]] = None,
license_info: Optional[dict[str, Union[str, Any]]] = None,
separate_input_output_schemas: bool = True,
external_docs: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
info: dict[str, Any] = {"title": title, "version": version}
if summary:
info["summary"] = summary
if description:
info["description"] = description
if terms_of_service:
info["termsOfService"] = terms_of_service
if contact:
info["contact"] = contact
if license_info:
info["license"] = license_info
output: dict[str, Any] = {"openapi": openapi_version, "info": info}
if servers:
output["servers"] = servers
components: dict[str, dict[str, Any]] = {}
paths: dict[str, dict[str, Any]] = {}
webhook_paths: dict[str, dict[str, Any]] = {}
operation_ids: set[str] = set()
all_fields = get_fields_from_routes(list(routes or []) + list(webhooks or []))
flat_models = get_flat_models_from_fields(all_fields, known_models=set())
model_name_map = get_model_name_map(flat_models)
field_mapping, definitions = get_definitions(
fields=all_fields,
model_name_map=model_name_map,
separate_input_output_schemas=separate_input_output_schemas,
)
for route in routes or []:
if isinstance(route, routing.APIRoute):
result = get_openapi_path(
route=route,
operation_ids=operation_ids,
model_name_map=model_name_map,
field_mapping=field_mapping,
separate_input_output_schemas=separate_input_output_schemas,
)
if result:
path, security_schemes, path_definitions = result
if path:
paths.setdefault(route.path_format, {}).update(path)
if security_schemes:
components.setdefault("securitySchemes", {}).update(
security_schemes
)
if path_definitions:
definitions.update(path_definitions)
for webhook in webhooks or []:
if isinstance(webhook, routing.APIRoute):
result = get_openapi_path(
route=webhook,
operation_ids=operation_ids,
model_name_map=model_name_map,
field_mapping=field_mapping,
separate_input_output_schemas=separate_input_output_schemas,
)
if result:
path, security_schemes, path_definitions = result
if path:
webhook_paths.setdefault(webhook.path_format, {}).update(path)
if security_schemes:
components.setdefault("securitySchemes", {}).update(
security_schemes
)
if path_definitions:
definitions.update(path_definitions)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does get_openapi() do?
get_openapi() is a function in the fastapi codebase, defined in fastapi/openapi/utils.py.
Where is get_openapi() defined?
get_openapi() is defined in fastapi/openapi/utils.py at line 480.
What does get_openapi() call?
get_openapi() calls 3 function(s): get_fields_from_routes, get_openapi_path, jsonable_encoder.
What calls get_openapi()?
get_openapi() is called by 2 function(s): custom_openapi, openapi.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free