From 81393afb350e14435449eb8568b753534a0eca85 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 27 Mar 2025 13:15:16 -0400 Subject: [PATCH] chore: require `data` field for all List*Response models (#1799) # What does this PR do? No violators are currently in-tree. This is just hardening the api specs for future consistency. Signed-off-by: Ihar Hrachyshka --- docs/openapi_generator/pyopenapi/utility.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/openapi_generator/pyopenapi/utility.py b/docs/openapi_generator/pyopenapi/utility.py index cb155fed7..47b72001b 100644 --- a/docs/openapi_generator/pyopenapi/utility.py +++ b/docs/openapi_generator/pyopenapi/utility.py @@ -146,9 +146,27 @@ def _validate_api_delete_method_returns_none(method) -> str | None: return "does not return None" +def _validate_list_parameters_contain_data(method) -> str | None: + hints = get_type_hints(method) + + if 'return' not in hints: + return "has no return type annotation" + + return_type = hints['return'] + if not inspect.isclass(return_type): + return + + if not return_type.__name__.startswith('List'): + return + + if 'data' not in return_type.model_fields: + return "does not have data attribute" + + _VALIDATORS = { "GET": [ _validate_api_method_return_type, + _validate_list_parameters_contain_data, ], "DELETE": [ _validate_api_delete_method_returns_none,