"""
),
] = True,
+ openapi_external_docs: Annotated[
+ Optional[Dict[str, Any]],
+ Doc(
+ """
+ This field allows you to provide additional external documentation links.
+ If provided, it must be a dictionary containing:
+
+ * `description`: A brief description of the external documentation.
+ * `url`: The URL pointing to the external documentation. The value **MUST**
+ be a valid URL format.
+
+ **Example**:
+
+ ```python
+ from fastapi import FastAPI
+
+ external_docs = {
+ "description": "Detailed API Reference",
+ "url": "https://example.com/api-docs",
+ }
+
+ app = FastAPI(openapi_external_docs=external_docs)
+ ```
+ """
+ ),
+ ] = None,
**extra: Annotated[
Any,
Doc(
self.swagger_ui_parameters = swagger_ui_parameters
self.servers = servers or []
self.separate_input_output_schemas = separate_input_output_schemas
+ self.openapi_external_docs = openapi_external_docs
self.extra = extra
self.openapi_version: Annotated[
str,
tags=self.openapi_tags,
servers=self.servers,
separate_input_output_schemas=self.separate_input_output_schemas,
+ external_docs=self.openapi_external_docs,
)
return self.openapi_schema
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:
output["webhooks"] = webhook_paths
if tags:
output["tags"] = tags
+ if external_docs:
+ output["externalDocs"] = external_docs
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
from fastapi import FastAPI, Path, Query
-app = FastAPI()
+external_docs = {
+ "description": "External API documentation.",
+ "url": "https://docs.example.com/api-general",
+}
+
+app = FastAPI(openapi_external_docs=external_docs)
@app.api_route("/api_route")
assert response.json() == {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
+ "externalDocs": {
+ "description": "External API documentation.",
+ "url": "https://docs.example.com/api-general",
+ },
"paths": {
"/api_route": {
"get": {