Skip to content

Commit f790623

Browse files
author
Mathieu Hinderyckx
committed
add formal test
1 parent 0b2f19e commit f790623

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@
8585
)
8686
from aws_lambda_powertools.event_handler.openapi.models import (
8787
Contact,
88+
ExternalDocumentation,
8889
License,
8990
OpenAPI,
9091
SecurityScheme,
9192
Server,
9293
Tag,
93-
ExternalDocumentation,
9494
)
9595
from aws_lambda_powertools.event_handler.openapi.params import Dependant
9696
from aws_lambda_powertools.event_handler.openapi.swagger_ui.oauth2 import (
@@ -1816,10 +1816,12 @@ def get_openapi_schema(
18161816
"info": info,
18171817
"servers": self._get_openapi_servers(servers),
18181818
"security": self._get_openapi_security(security, security_schemes),
1819-
"external_docs": external_documentation,
18201819
**openapi_extensions,
18211820
}
18221821

1822+
if external_documentation:
1823+
output["external_docs"] = external_documentation
1824+
18231825
components: dict[str, dict[str, Any]] = {}
18241826
paths: dict[str, dict[str, Any]] = {}
18251827
operation_ids: set[str] = set()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import annotations
2+
3+
from aws_lambda_powertools.event_handler.api_gateway import APIGatewayRestResolver
4+
from aws_lambda_powertools.event_handler.openapi.models import ExternalDocumentation, Server
5+
6+
7+
def test_openapi_schema_no_external_documentation():
8+
app = APIGatewayRestResolver()
9+
10+
schema = app.get_openapi_schema(title="Hello API", version="1.0.0")
11+
assert not schema.externalDocs
12+
13+
14+
def test_openapi_schema_external_documentation():
15+
app = APIGatewayRestResolver()
16+
17+
schema = app.get_openapi_schema(
18+
title="Hello API",
19+
version="1.0.0",
20+
external_documentation=ExternalDocumentation(
21+
description="Find out more about this API",
22+
url="https://example.org/docs",
23+
),
24+
)
25+
26+
assert schema.externalDocs
27+
assert schema.externalDocs.description == "Find out more about this API"
28+
assert schema.externalDocs.url == "https://example.org/docs"

0 commit comments

Comments
 (0)