Skip to content

Commit 0b2f19e

Browse files
author
Mathieu Hinderyckx
committed
Add top-level externalDocs support
1 parent cf80289 commit 0b2f19e

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
SecurityScheme,
9191
Server,
9292
Tag,
93+
ExternalDocumentation,
9394
)
9495
from aws_lambda_powertools.event_handler.openapi.params import Dependant
9596
from aws_lambda_powertools.event_handler.openapi.swagger_ui.oauth2 import (
@@ -1714,6 +1715,7 @@ def get_openapi_schema(
17141715
license_info: License | None = None,
17151716
security_schemes: dict[str, SecurityScheme] | None = None,
17161717
security: list[dict[str, list[str]]] | None = None,
1718+
external_documentation: ExternalDocumentation | None = None,
17171719
openapi_extensions: dict[str, Any] | None = None,
17181720
) -> OpenAPI:
17191721
"""
@@ -1745,6 +1747,8 @@ def get_openapi_schema(
17451747
A declaration of the security schemes available to be used in the specification.
17461748
security: list[dict[str, list[str]]], optional
17471749
A declaration of which security mechanisms are applied globally across the API.
1750+
external_documentation: ExternalDocumentation, optional
1751+
Additional external documentation for the API.
17481752
openapi_extensions: Dict[str, Any], optional
17491753
Additional OpenAPI extensions as a dictionary.
17501754
@@ -1775,6 +1779,7 @@ def get_openapi_schema(
17751779
license_info = license_info or self.openapi_config.license_info
17761780
security_schemes = security_schemes or self.openapi_config.security_schemes
17771781
security = security or self.openapi_config.security
1782+
external_documentation = external_documentation or self.openapi_config.external_documentation
17781783
openapi_extensions = openapi_extensions or self.openapi_config.openapi_extensions
17791784

17801785
from pydantic.json_schema import GenerateJsonSchema
@@ -1811,6 +1816,7 @@ def get_openapi_schema(
18111816
"info": info,
18121817
"servers": self._get_openapi_servers(servers),
18131818
"security": self._get_openapi_security(security, security_schemes),
1819+
"external_docs": external_documentation,
18141820
**openapi_extensions,
18151821
}
18161822

@@ -1921,6 +1927,7 @@ def get_openapi_json_schema(
19211927
license_info: License | None = None,
19221928
security_schemes: dict[str, SecurityScheme] | None = None,
19231929
security: list[dict[str, list[str]]] | None = None,
1930+
external_documentation: ExternalDocumentation | None = None,
19241931
openapi_extensions: dict[str, Any] | None = None,
19251932
) -> str:
19261933
"""
@@ -1952,6 +1959,8 @@ def get_openapi_json_schema(
19521959
A declaration of the security schemes available to be used in the specification.
19531960
security: list[dict[str, list[str]]], optional
19541961
A declaration of which security mechanisms are applied globally across the API.
1962+
external_documentation: ExternalDocumentation, optional
1963+
Additional external documentation for the API.
19551964
openapi_extensions: Dict[str, Any], optional
19561965
Additional OpenAPI extensions as a dictionary.
19571966
@@ -1977,6 +1986,7 @@ def get_openapi_json_schema(
19771986
license_info=license_info,
19781987
security_schemes=security_schemes,
19791988
security=security,
1989+
external_documentation=external_documentation,
19801990
openapi_extensions=openapi_extensions,
19811991
),
19821992
by_alias=True,
@@ -1998,6 +2008,7 @@ def configure_openapi(
19982008
license_info: License | None = None,
19992009
security_schemes: dict[str, SecurityScheme] | None = None,
20002010
security: list[dict[str, list[str]]] | None = None,
2011+
external_documentation: ExternalDocumentation | None = None,
20012012
openapi_extensions: dict[str, Any] | None = None,
20022013
):
20032014
"""Configure OpenAPI specification settings for the API.
@@ -2031,6 +2042,8 @@ def configure_openapi(
20312042
A declaration of the security schemes available to be used in the specification.
20322043
security: list[dict[str, list[str]]], optional
20332044
A declaration of which security mechanisms are applied globally across the API.
2045+
external_documentation: ExternalDocumentation, optional
2046+
A link to external documentation for the API.
20342047
openapi_extensions: Dict[str, Any], optional
20352048
Additional OpenAPI extensions as a dictionary.
20362049
@@ -2064,6 +2077,7 @@ def configure_openapi(
20642077
license_info=license_info,
20652078
security_schemes=security_schemes,
20662079
security=security,
2080+
external_documentation=external_documentation,
20672081
openapi_extensions=openapi_extensions,
20682082
)
20692083

@@ -2088,6 +2102,7 @@ def enable_swagger(
20882102
security: list[dict[str, list[str]]] | None = None,
20892103
oauth2_config: OAuth2Config | None = None,
20902104
persist_authorization: bool = False,
2105+
external_documentation: ExternalDocumentation | None = None,
20912106
openapi_extensions: dict[str, Any] | None = None,
20922107
):
20932108
"""
@@ -2131,6 +2146,8 @@ def enable_swagger(
21312146
The OAuth2 configuration for the Swagger UI.
21322147
persist_authorization: bool, optional
21332148
Whether to persist authorization data on browser close/refresh.
2149+
external_documentation: ExternalDocumentation, optional
2150+
A link to external documentation for the API.
21342151
openapi_extensions: dict[str, Any], optional
21352152
Additional OpenAPI extensions as a dictionary.
21362153
"""
@@ -2183,6 +2200,7 @@ def swagger_handler():
21832200
license_info=license_info,
21842201
security_schemes=security_schemes,
21852202
security=security,
2203+
external_documentation=external_documentation,
21862204
openapi_extensions=openapi_extensions,
21872205
)
21882206

aws_lambda_powertools/event_handler/openapi/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
SecurityScheme,
1717
Server,
1818
Tag,
19+
ExternalDocumentation,
1920
)
2021

2122

@@ -51,6 +52,8 @@ class OpenAPIConfig:
5152
A declaration of the security schemes available to be used in the specification.
5253
security: list[dict[str, list[str]]], optional
5354
A declaration of which security mechanisms are applied globally across the API.
55+
external_documentation: ExternalDocumentation, optional
56+
A link to external documentation for the API.
5457
openapi_extensions: Dict[str, Any], optional
5558
Additional OpenAPI extensions as a dictionary.
5659
@@ -77,4 +80,5 @@ class OpenAPIConfig:
7780
license_info: License | None = None
7881
security_schemes: dict[str, SecurityScheme] | None = None
7982
security: list[dict[str, list[str]]] | None = None
83+
external_documentation: ExternalDocumentation | None = None
8084
openapi_extensions: dict[str, Any] | None = None

0 commit comments

Comments
 (0)