MCPcopy
hub / github.com/fastapi/fastapi / openapi

Method openapi

fastapi/applications.py:1070–1103  ·  view source on GitHub ↗

Generate the OpenAPI schema of the application. This is called by FastAPI internally. The first time it is called it stores the result in the attribute `app.openapi_schema`, and next times it is called, it just returns that same result. To avoid the cost of

(self)

Source from the content-addressed store, hash-verified

1068 return app
1069
1070 def openapi(self) -> dict[str, Any]:
1071 """
1072 Generate the OpenAPI schema of the application. This is called by FastAPI
1073 internally.
1074
1075 The first time it is called it stores the result in the attribute
1076 `app.openapi_schema`, and next times it is called, it just returns that same
1077 result. To avoid the cost of generating the schema every time.
1078
1079 If you need to modify the generated OpenAPI schema, you could modify it.
1080
1081 Read more in the
1082 [FastAPI docs for OpenAPI](https://fastapi.tiangolo.com/how-to/extending-openapi/).
1083 """
1084 routes_version = self.router._get_routes_version()
1085 if not self.openapi_schema or self._openapi_routes_version != routes_version:
1086 self.openapi_schema = get_openapi(
1087 title=self.title,
1088 version=self.version,
1089 openapi_version=self.openapi_version,
1090 summary=self.summary,
1091 description=self.description,
1092 terms_of_service=self.terms_of_service,
1093 contact=self.contact,
1094 license_info=self.license_info,
1095 routes=self.routes,
1096 webhooks=self.webhooks.routes,
1097 tags=self.openapi_tags,
1098 servers=self.servers,
1099 separate_input_output_schemas=self.separate_input_output_schemas,
1100 external_docs=self.openapi_external_docs,
1101 )
1102 self._openapi_routes_version = routes_version
1103 return self.openapi_schema
1104
1105 def setup(self) -> None:
1106 if self.openapi_url:

Calls 3

get_openapiFunction · 0.90
_get_routes_versionMethod · 0.80
getMethod · 0.45