1.3.0
This commit is contained in:
@@ -15,21 +15,257 @@ from tests.conftest import SDKFunction
|
||||
|
||||
|
||||
expected_inconsistencies: list[str] = [
|
||||
'''cloudapi.sep.list_available_sep_and_pools: result type must be child of BaseAPIParamsNestedModel.''', # noqa E501
|
||||
'''cloudapi.k8s.create: parameter "lb_sysctl_params", target_annotation = dict[str, str], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa E501
|
||||
'cloudbroker.storage_policy.get: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudbroker.storage_policy.add_pool: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'''cloudapi.lb.create: parameter "sysctl_params", target_annotation = dict[str, str], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa E501
|
||||
'cloudbroker.storage_policy.delete_pool: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudbroker.storage_policy.update: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudapi.zone.list: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudapi.storage_policy.get: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'''cloudapi.compute.guest_agent_execute: parameter "args", target_annotation = dict[str, typing.Any], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa: E501
|
||||
'''cloudapi.image.create: API has parameter "asyncMode" but this SDK function doesn't have corresponding parameter.''', # noqa: E501
|
||||
'''cloudapi.flipgroup.create: API has parameter "clientType" but this SDK function doesn't have corresponding parameter.''', # noqa: E501
|
||||
'''cloudapi.k8s.create: API has parameter "oidcCertificate" but this SDK function doesn't have corresponding parameter.''', # noqa: E501
|
||||
'cloudapi.k8s.create: annotation of parameter "lb_sysctl_params" must contain BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudapi.user.get_audit: result type must be child of BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudapi.disks.limit_io: API has parameter "iops" but this SDK function doesn\'t have corresponding parameter.', # noqa: E501
|
||||
'cloudapi.bservice.group_stop: default value of parameter "force" must be None.', # noqa: E501
|
||||
'cloudapi.bservice.group_stop: annotation of parameter "force" must be Union.', # noqa: E501
|
||||
'cloudapi.compute.net_attach: result type must be child of BaseAPIResultBool.', # noqa: E501
|
||||
'cloudapi.compute.net_attach: default value of parameter "mtu" must be 1500.', # noqa: E501
|
||||
'cloudapi.disks.create: default value of parameter "size_gb" must be 10.',
|
||||
'cloudapi.kvmx86.create: annotation of parameter "ci_user_data" must contain BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'cloudapi.lb.create: annotation of parameter "sysctl_params" must contain BaseAPIParamsNestedModel.', # noqa: E501
|
||||
'''cloudapi.lb.update_sysctl_params: parameter "sysctl_params", target_annotation = dict[str, str], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa: E501
|
||||
'''cloudbroker.compute.start_migration_out: parameter "disk_mapping", target_annotation = dict[str, str], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa E501
|
||||
'''cloudbroker.compute.start_migration_out: parameter "cdrom_mapping", target_annotation = dict[str, str], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa E501
|
||||
'''cloudbroker.compute.start_migration_out: parameter "net_mapping", target_annotation = dict[str, dynamix_sdk.api._nested.params.NetMapConfigAPIParamsNM], expected_annot = <class 'dynamix_sdk.base.BaseAPIParamsNestedModel'>''', # noqa E501
|
||||
'cloudbroker.user.create: default value of parameter "password" must be strongpassword.', # noqa: E501
|
||||
]
|
||||
|
||||
type_mappings = {
|
||||
'integer': int,
|
||||
'string': str,
|
||||
'boolean': bool,
|
||||
'object': sdk_types.BaseAPIParamsNestedModel,
|
||||
'number': float,
|
||||
'dict': sdk_types.BaseAPIResultModel,
|
||||
'array': list,
|
||||
}
|
||||
|
||||
|
||||
def check_param(
|
||||
*,
|
||||
sdk_func_name: str,
|
||||
sdk_func_params: dict[str, inspect.Parameter],
|
||||
param_name: str,
|
||||
param_def: dict,
|
||||
required: bool,
|
||||
) -> list[str]:
|
||||
inconsistencies: list[str] = []
|
||||
api_def_param_enum = param_def.get('enum')
|
||||
if (
|
||||
api_def_param_enum is not None
|
||||
and not isinstance(api_def_param_enum, list)
|
||||
):
|
||||
raise TypeError
|
||||
|
||||
api_def_param_default = param_def.get('default')
|
||||
api_def_param_type = param_def.get('type')
|
||||
if (
|
||||
api_def_param_type is not None
|
||||
and not isinstance(api_def_param_type, str)
|
||||
):
|
||||
raise TypeError
|
||||
|
||||
api_def_param_items = param_def.get('items')
|
||||
if (
|
||||
api_def_param_items is not None
|
||||
and not isinstance(api_def_param_items, dict)
|
||||
):
|
||||
raise TypeError
|
||||
|
||||
necessary_dx_param = required or not (
|
||||
api_def_param_enum
|
||||
and len(api_def_param_enum) == 1
|
||||
and api_def_param_default is not None
|
||||
)
|
||||
|
||||
if not isinstance(param_name, str):
|
||||
raise TypeError
|
||||
|
||||
param_exists_in_sdk = param_name in sdk_func_params.keys()
|
||||
|
||||
if not param_exists_in_sdk:
|
||||
if necessary_dx_param:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' API has parameter "{param_name}"'
|
||||
f" but this SDK function doesn't have"
|
||||
f' corresponding parameter.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
sdk_func_param = sdk_func_params[param_name]
|
||||
sdk_param_name = sdk_func_param.name
|
||||
|
||||
if not necessary_dx_param:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' parameter "{sdk_param_name} is unnecessary in SDK.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
if sdk_func_param.annotation is Any:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must not be Any.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
if api_def_param_default and api_def_param_default != -1:
|
||||
if sdk_func_param.default != api_def_param_default:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' default value of parameter "{sdk_param_name}"'
|
||||
f' must be {api_def_param_default}.'
|
||||
)
|
||||
|
||||
target_annotation = sdk_func_param.annotation
|
||||
if not required and (
|
||||
api_def_param_default is None
|
||||
or (api_def_param_default == 0 and api_def_param_default is not False)
|
||||
or api_def_param_default == ''
|
||||
or api_def_param_default == -1
|
||||
or api_def_param_default == []
|
||||
):
|
||||
if sdk_func_param.default is not None:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' default value of parameter "{sdk_param_name}"'
|
||||
f' must be None.'
|
||||
)
|
||||
|
||||
if not isinstance(sdk_func_param.annotation, UnionType):
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must be Union.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
annot_union_args = get_args(sdk_func_param.annotation)
|
||||
if NoneType not in annot_union_args:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain None.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
if not len(annot_union_args) == 2:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain two types.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
if annot_union_args[0] is NoneType:
|
||||
target_annotation = annot_union_args[1]
|
||||
else:
|
||||
target_annotation = annot_union_args[0]
|
||||
|
||||
if api_def_param_type == 'array':
|
||||
if (
|
||||
not isinstance(target_annotation, GenericAlias)
|
||||
or target_annotation.__origin__ is not list
|
||||
):
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain list[...]'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
if api_def_param_items is not None:
|
||||
api_def_param_items_type = api_def_param_items.get('type')
|
||||
if api_def_param_items_type is None:
|
||||
return inconsistencies
|
||||
if not isinstance(api_def_param_items_type, str):
|
||||
raise TypeError
|
||||
|
||||
target_annotation = get_args(target_annotation)[0]
|
||||
expected_annot = type_mappings.get(api_def_param_items_type)
|
||||
if expected_annot is None:
|
||||
return inconsistencies
|
||||
|
||||
elif api_def_param_type is not None:
|
||||
expected_annot = type_mappings.get(api_def_param_type)
|
||||
if expected_annot is None:
|
||||
return inconsistencies
|
||||
|
||||
if (
|
||||
not inspect.isclass(target_annotation)
|
||||
or isinstance(target_annotation, GenericAlias)
|
||||
):
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' parameter "{sdk_param_name}",'
|
||||
f' {target_annotation = },' # noqa: E202, E251
|
||||
f' {expected_annot = }' # noqa: E202, E251
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
if api_def_param_enum:
|
||||
if not issubclass(target_annotation, Enum):
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain enum.'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
enum_from_annot = target_annotation
|
||||
enum_values = [e.value for e in enum_from_annot]
|
||||
if sorted(api_def_param_enum) != sorted(enum_values):
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' parameter "{sdk_param_name}":'
|
||||
f' enum {enum_from_annot.__qualname__}'
|
||||
f' must contain these values:'
|
||||
f' {api_def_param_enum}.'
|
||||
)
|
||||
elif not issubclass(target_annotation, expected_annot):
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain {expected_annot.__qualname__}.'
|
||||
)
|
||||
|
||||
return inconsistencies
|
||||
|
||||
|
||||
def find_unused_sdk_params(
|
||||
*,
|
||||
sdk_func_name: str,
|
||||
sdk_func_params: dict[str, inspect.Parameter],
|
||||
dx_param_names: set[str],
|
||||
) -> list[str]:
|
||||
inconsistencies: list[str] = []
|
||||
unused_sdk_param_names = [
|
||||
sdk_param.name
|
||||
for alias, sdk_param in sdk_func_params.items()
|
||||
if alias not in dx_param_names
|
||||
]
|
||||
|
||||
if unused_sdk_param_names:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}:'
|
||||
f' unused parameters:'
|
||||
f' {", ".join(sorted(unused_sdk_param_names))}'
|
||||
)
|
||||
return inconsistencies
|
||||
|
||||
|
||||
def test_with_api_definition(
|
||||
dx_api_definition: JSON,
|
||||
@@ -37,6 +273,7 @@ def test_with_api_definition(
|
||||
):
|
||||
inconsistencies: list[str] = []
|
||||
for sdk_func in sdk_dx_functions:
|
||||
sdk_func_name = ".".join(sdk_func.call_attrs)
|
||||
func_full_api_path = f'/restmachine{sdk_func.url_path}'
|
||||
|
||||
if not isinstance(dx_api_definition, dict):
|
||||
@@ -49,7 +286,7 @@ def test_with_api_definition(
|
||||
|
||||
if func_full_api_path not in dx_api_definition_paths:
|
||||
inconsistencies.append(
|
||||
f"{'.'.join(sdk_func.call_attrs)}:"
|
||||
f"{sdk_func_name}:"
|
||||
f' url path {sdk_func.url_path} not found in'
|
||||
f' DX API definition.'
|
||||
)
|
||||
@@ -66,7 +303,7 @@ def test_with_api_definition(
|
||||
m.upper() for m in func_api_definition.keys()
|
||||
]
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f'{sdk_func_name}:'
|
||||
f' HTTP method {sdk_func.http_method} not found.'
|
||||
f' DX API definition for {sdk_func.url_path} has'
|
||||
f' only these HTTP methods:'
|
||||
@@ -78,14 +315,6 @@ def test_with_api_definition(
|
||||
if not isinstance(func_api_def_method, dict):
|
||||
raise TypeError
|
||||
|
||||
type_mappings = {
|
||||
'integer': int,
|
||||
'string': str,
|
||||
'boolean': bool,
|
||||
'object': sdk_types.BaseAPIParamsNestedModel,
|
||||
'number': float,
|
||||
}
|
||||
|
||||
if api_def_result_type := get_nested_value(
|
||||
d=func_api_def_method,
|
||||
keys=('responses', '200', 'schema', 'type'),
|
||||
@@ -95,7 +324,7 @@ def test_with_api_definition(
|
||||
expected_result_type = sdk_types.BaseAPIResultBool
|
||||
if not issubclass(sdk_func.result_cls, expected_result_type):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f'{sdk_func_name}:'
|
||||
f' result type must be child of'
|
||||
f' {expected_result_type.__qualname__}.'
|
||||
)
|
||||
@@ -111,222 +340,86 @@ def test_with_api_definition(
|
||||
)
|
||||
sdk_func_params[alias] = p
|
||||
|
||||
api_definition_params = func_api_def_method.get('parameters')
|
||||
if not api_definition_params:
|
||||
if sdk_func_params:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' this function must not have parameters.'
|
||||
)
|
||||
continue
|
||||
api_definition_params = func_api_def_method.get('parameters') or []
|
||||
body_schema = None
|
||||
|
||||
if not isinstance(api_definition_params, list):
|
||||
raise TypeError
|
||||
|
||||
dx_param_names = set()
|
||||
for p in api_definition_params:
|
||||
if not isinstance(p, dict):
|
||||
raise TypeError
|
||||
dx_param_names.add(p['name'])
|
||||
if (
|
||||
isinstance(p, dict)
|
||||
and p.get('name') == 'body' and 'schema' in p
|
||||
):
|
||||
body_schema = p['schema']
|
||||
break
|
||||
|
||||
if len(sdk_func_params) > len(dx_param_names):
|
||||
unused_sdk_param_names = []
|
||||
for sdk_param_alias, sdk_param in sdk_func_params.items():
|
||||
if sdk_param_alias not in dx_param_names:
|
||||
unused_sdk_param_names.append(sdk_param.name)
|
||||
if unused_sdk_param_names:
|
||||
dx_param_names = set()
|
||||
param_defs = dict()
|
||||
required_params = set()
|
||||
|
||||
if isinstance(body_schema, dict) and 'properties' in body_schema:
|
||||
properties = body_schema['properties']
|
||||
|
||||
if not isinstance(properties, dict):
|
||||
raise TypeError
|
||||
|
||||
required = body_schema.get('required', [])
|
||||
if not isinstance(required, list):
|
||||
raise TypeError
|
||||
|
||||
dx_param_names.update(properties.keys())
|
||||
param_defs.update(properties)
|
||||
required_params.update(required)
|
||||
|
||||
else:
|
||||
if not api_definition_params:
|
||||
if sdk_func_params:
|
||||
inconsistencies.append(
|
||||
f'{sdk_func_name}: this function '
|
||||
f'must not have parameters.'
|
||||
)
|
||||
continue
|
||||
|
||||
for p in api_definition_params:
|
||||
if not isinstance(p, dict):
|
||||
raise TypeError
|
||||
param_name = p['name']
|
||||
if not isinstance(param_name, str):
|
||||
raise TypeError
|
||||
|
||||
dx_param_names.add(param_name)
|
||||
param_defs[param_name] = p
|
||||
if p.get('required', False):
|
||||
required_params.add(param_name)
|
||||
|
||||
if not dx_param_names:
|
||||
if sdk_func_params:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' unused parameters:'
|
||||
f' {", ".join(sorted(unused_sdk_param_names))}'
|
||||
f"{sdk_func_name}: this function must not have parameters."
|
||||
)
|
||||
else:
|
||||
inconsistencies.extend(
|
||||
find_unused_sdk_params(
|
||||
sdk_func_name=sdk_func_name,
|
||||
sdk_func_params=sdk_func_params,
|
||||
dx_param_names=dx_param_names,
|
||||
)
|
||||
|
||||
for api_def_param in api_definition_params:
|
||||
if not isinstance(api_def_param, dict):
|
||||
raise TypeError
|
||||
|
||||
api_def_param_enum = api_def_param.get('enum')
|
||||
if (
|
||||
api_def_param_enum is not None
|
||||
and not isinstance(api_def_param_enum, list)
|
||||
):
|
||||
raise TypeError
|
||||
|
||||
api_def_param_default = api_def_param.get('default')
|
||||
|
||||
api_def_param_type = api_def_param.get('type')
|
||||
if (
|
||||
api_def_param_type is not None
|
||||
and not isinstance(api_def_param_type, str)
|
||||
):
|
||||
raise TypeError
|
||||
|
||||
api_def_param_items = api_def_param.get('items')
|
||||
if (
|
||||
api_def_param_items is not None
|
||||
and not isinstance(api_def_param_items, dict)
|
||||
):
|
||||
raise TypeError
|
||||
|
||||
necessary_dx_param = not (
|
||||
api_def_param_enum
|
||||
and len(api_def_param_enum) == 1
|
||||
and api_def_param_default is not None
|
||||
)
|
||||
|
||||
sdk_param_alias = api_def_param['name']
|
||||
if not isinstance(sdk_param_alias, str):
|
||||
raise TypeError
|
||||
for param_name, param_def in param_defs.items():
|
||||
if not isinstance(param_def, dict):
|
||||
raise TypeError
|
||||
|
||||
param_exists_in_sdk = sdk_param_alias in sdk_func_params.keys()
|
||||
|
||||
if not param_exists_in_sdk:
|
||||
if necessary_dx_param:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' API has parameter "{sdk_param_alias}"'
|
||||
f" but this SDK function doesn't have"
|
||||
f' corresponding parameter.'
|
||||
inconsistencies.extend(
|
||||
check_param(
|
||||
sdk_func_name=sdk_func_name,
|
||||
sdk_func_params=sdk_func_params,
|
||||
param_name=param_name,
|
||||
param_def=param_def,
|
||||
required=param_name in required_params,
|
||||
)
|
||||
continue
|
||||
|
||||
sdk_param_name = sdk_func_params[sdk_param_alias].name
|
||||
|
||||
if not necessary_dx_param:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' parameter "{sdk_param_name} is unnecessary in SDK.'
|
||||
)
|
||||
continue
|
||||
|
||||
sdk_func_param = sdk_func_params[sdk_param_alias]
|
||||
|
||||
if sdk_func_param.annotation is Any:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must not be Any.'
|
||||
)
|
||||
continue
|
||||
|
||||
if api_def_param_default and api_def_param_default != -1:
|
||||
if sdk_func_param.default != api_def_param_default:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' default value of parameter "{sdk_param_name}"'
|
||||
f' must be {api_def_param_default}.'
|
||||
)
|
||||
|
||||
target_annotation = sdk_func_param.annotation
|
||||
if not api_def_param.get('required') and (
|
||||
api_def_param_default is None
|
||||
or (
|
||||
api_def_param_default == 0
|
||||
and api_def_param_default is not False
|
||||
)
|
||||
or api_def_param_default == ''
|
||||
or api_def_param_default == -1
|
||||
):
|
||||
if sdk_func_param.default is not None:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' default value of parameter "{sdk_param_name}"'
|
||||
f' must be None.'
|
||||
)
|
||||
|
||||
if not isinstance(sdk_func_param.annotation, UnionType):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must be Union.'
|
||||
)
|
||||
continue
|
||||
|
||||
annot_union_args = get_args(sdk_func_param.annotation)
|
||||
if NoneType not in annot_union_args:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain None.'
|
||||
)
|
||||
continue
|
||||
|
||||
if not len(annot_union_args) == 2:
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain two types.'
|
||||
)
|
||||
continue
|
||||
|
||||
if annot_union_args[0] is NoneType:
|
||||
target_annotation = annot_union_args[1]
|
||||
else:
|
||||
target_annotation = annot_union_args[0]
|
||||
|
||||
if api_def_param_type == 'array':
|
||||
if (
|
||||
not isinstance(target_annotation, GenericAlias)
|
||||
or target_annotation.__origin__ is not list
|
||||
):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain list[...].'
|
||||
)
|
||||
continue
|
||||
|
||||
if api_def_param_items is not None:
|
||||
api_def_param_items_type = api_def_param_items.get('type')
|
||||
if api_def_param_items_type is None:
|
||||
continue
|
||||
if not isinstance(api_def_param_items_type, str):
|
||||
raise TypeError
|
||||
|
||||
target_annotation = get_args(target_annotation)[0]
|
||||
expected_annot = type_mappings.get(
|
||||
api_def_param_items_type
|
||||
)
|
||||
if expected_annot is None:
|
||||
continue
|
||||
elif api_def_param_type is not None:
|
||||
expected_annot = type_mappings.get(api_def_param_type)
|
||||
if expected_annot is None:
|
||||
continue
|
||||
|
||||
if not inspect.isclass(target_annotation):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' parameter "{sdk_param_name}",'
|
||||
f' {target_annotation = },' # noqa: E202, E251
|
||||
f' {expected_annot = }' # noqa: E202, E251
|
||||
)
|
||||
continue
|
||||
|
||||
if api_def_param_enum:
|
||||
if not issubclass(target_annotation, Enum):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain enum.'
|
||||
)
|
||||
continue
|
||||
enum_from_annot = target_annotation
|
||||
enum_values = enum_from_annot.__members__.values()
|
||||
if sorted(api_def_param_enum) != sorted(enum_values):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' parameter "{sdk_param_name}":'
|
||||
f' enum {enum_from_annot.__qualname__}'
|
||||
f' must contain these values: {api_def_param_enum}.'
|
||||
)
|
||||
elif not issubclass(target_annotation, expected_annot):
|
||||
inconsistencies.append(
|
||||
f'{".".join(sdk_func.call_attrs)}:'
|
||||
f' annotation of parameter "{sdk_param_name}"'
|
||||
f' must contain {expected_annot.__qualname__}.'
|
||||
)
|
||||
continue
|
||||
|
||||
for expected_inconsistency in expected_inconsistencies:
|
||||
if expected_inconsistency in inconsistencies:
|
||||
|
||||
Reference in New Issue
Block a user