Skip to content

Commit e9d1c31

Browse files
committed
fix: refactor
1 parent d7792fd commit e9d1c31

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

aws_lambda_powertools/event_handler/openapi/dependant.py

+28-20
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ def get_dependant(
199199
else:
200200
add_param_to_fields(field=param_field, dependant=dependant)
201201

202+
_add_return_annotation(dependant, endpoint_signature)
203+
_add_extra_responses(dependant, responses)
204+
205+
return dependant
206+
207+
208+
def _add_extra_responses(dependant: Dependant, responses: Optional[Dict[int, OpenAPIResponse]]):
209+
# Also add the optional extra responses to the dependant model.
210+
if not responses:
211+
return
212+
213+
for response in responses.values():
214+
for schema in response.get("content", {}).values():
215+
if "model" in schema:
216+
response_field = analyze_param(
217+
param_name="return",
218+
annotation=cast(OpenAPIResponseContentModel, schema)["model"],
219+
value=None,
220+
is_path_param=False,
221+
is_response_param=True,
222+
)
223+
if response_field is None:
224+
raise AssertionError("Response field is None for response model")
225+
226+
dependant.response_extra_models.append(response_field)
227+
228+
229+
def _add_return_annotation(dependant: Dependant, endpoint_signature: inspect.Signature):
202230
# If the return annotation is not empty, add it to the dependant model.
203231
return_annotation = endpoint_signature.return_annotation
204232
if return_annotation is not inspect.Signature.empty:
@@ -214,26 +242,6 @@ def get_dependant(
214242

215243
dependant.return_param = param_field
216244

217-
# Also add the optional extra responses to the dependant model.
218-
if responses:
219-
for response in responses.values():
220-
if "content" in response:
221-
for schema in response["content"].values():
222-
if "model" in schema:
223-
response_field = analyze_param(
224-
param_name="return",
225-
annotation=cast(OpenAPIResponseContentModel, schema)["model"],
226-
value=None,
227-
is_path_param=False,
228-
is_response_param=True,
229-
)
230-
if response_field is None:
231-
raise AssertionError("Response field is None for response model")
232-
233-
dependant.response_extra_models.append(response_field)
234-
235-
return dependant
236-
237245

238246
def is_body_param(*, param_field: ModelField, is_path_param: bool) -> bool:
239247
"""

0 commit comments

Comments
 (0)