MCPcopy
hub / github.com/fastapi/fastapi / get_openapi

Function get_openapi

fastapi/openapi/utils.py:523–617  ·  view source on GitHub ↗
(
    *,
    title: str,
    version: str,
    openapi_version: str = "3.1.0",
    summary: str | None = None,
    description: str | None = None,
    routes: Sequence[BaseRoute | routing.RouteContext],
    webhooks: Sequence[BaseRoute | routing.RouteContext] | None = None,
    tags: list[dict[str, Any]] | None = None,
    servers: list[dict[str, str | Any]] | None = None,
    terms_of_service: str | None = None,
    contact: dict[str, str | Any] | None = None,
    license_info: dict[str, str | Any] | None = None,
    separate_input_output_schemas: bool = True,
    external_docs: dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

521
522
523def get_openapi(
524 *,
525 title: str,
526 version: str,
527 openapi_version: str = "3.1.0",
528 summary: str | None = None,
529 description: str | None = None,
530 routes: Sequence[BaseRoute | routing.RouteContext],
531 webhooks: Sequence[BaseRoute | routing.RouteContext] | None = None,
532 tags: list[dict[str, Any]] | None = None,
533 servers: list[dict[str, str | Any]] | None = None,
534 terms_of_service: str | None = None,
535 contact: dict[str, str | Any] | None = None,
536 license_info: dict[str, str | Any] | None = None,
537 separate_input_output_schemas: bool = True,
538 external_docs: dict[str, Any] | None = None,
539) -> dict[str, Any]:
540 info: dict[str, Any] = {"title": title, "version": version}
541 if summary:
542 info["summary"] = summary
543 if description:
544 info["description"] = description
545 if terms_of_service:
546 info["termsOfService"] = terms_of_service
547 if contact:
548 info["contact"] = contact
549 if license_info:
550 info["license"] = license_info
551 output: dict[str, Any] = {"openapi": openapi_version, "info": info}
552 if servers:
553 output["servers"] = servers
554 components: dict[str, dict[str, Any]] = {}
555 paths: dict[str, dict[str, Any]] = {}
556 webhook_paths: dict[str, dict[str, Any]] = {}
557 operation_ids: set[str] = set()
558 all_fields = get_fields_from_routes(list(routes) + list(webhooks or []))
559 flat_models = get_flat_models_from_fields(all_fields, known_models=set())
560 model_name_map = get_model_name_map(flat_models)
561 field_mapping, definitions = get_definitions(
562 fields=all_fields,
563 model_name_map=model_name_map,
564 separate_input_output_schemas=separate_input_output_schemas,
565 )
566 for route_context in routing.iter_route_contexts(routes):
567 api_route = _get_api_route_for_openapi(route_context)
568 if api_route is not None:
569 result = get_openapi_path(
570 route=api_route,
571 operation_ids=operation_ids,
572 model_name_map=model_name_map,
573 field_mapping=field_mapping,
574 separate_input_output_schemas=separate_input_output_schemas,
575 )
576 if result:
577 path, security_schemes, path_definitions = result
578 if path:
579 paths.setdefault(api_route.path_format, {}).update(path)
580 if security_schemes:

Calls 8

get_model_name_mapFunction · 0.90
get_definitionsFunction · 0.90
jsonable_encoderFunction · 0.90
OpenAPIClass · 0.90
get_fields_from_routesFunction · 0.85
get_openapi_pathFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…