forked from phoenix-oss/llama-stack-mirror
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 <ihar.hrachyshka@gmail.com>
This commit is contained in:
parent
935e706b15
commit
81393afb35
1 changed files with 18 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue