Update neutron schema resolution

Neutron treats subnetpool.XXX_prefixlen everywhere as integers including
the database (it is even described like that in neutron api-ref itself).
For some unknown reason it returns it as a string though. Maybe because
in the apidef it is defined like `validate: "type:non_negative",
convert_to: convert_to_int`. Modify api_def processing not to look at
validate OR convert_to, but use convert_to results in update of the
schema.

Change-Id: I52d1d207be54967a0a1b9a3443c661b1fabd69f4
This commit is contained in:
Artem Goncharov
2024-08-07 14:31:02 +02:00
parent b19632ddd3
commit 7931cdee83
2 changed files with 30 additions and 9 deletions

View File

@@ -780,10 +780,31 @@ class TypeManager:
if typ["class"] == number_klass:
kinds.remove(typ)
elif string_klass in kinds_classes and integer_klass in kinds_classes:
if enum_name and (
enum_name.endswith("size") or enum_name.endswith("count")
):
int_klass = next(
(
x
for x in type_model.kinds
if isinstance(x, model.ConstraintInteger)
)
)
if (
# XX_size or XX_count is clearly an integer
(
enum_name
and (
enum_name.endswith("size")
or enum_name.endswith("count")
)
)
# There is certain limit (min/max) - it can be only integer
or (
int_klass
and (
int_klass.minimum is not None
or int_klass.maximum is not None
)
)
):
for typ in list(kinds):
if typ["class"] == string_klass:
kinds.remove(typ)

View File

@@ -1377,18 +1377,18 @@ def get_schema(param_data):
"Unsupported type %s in %s" % (validate, param_data)
)
schema = {"type": "string"}
elif convert_to:
if convert_to:
# Nice way to get type of the field, isn't it?
if convert_to.__name__ == "convert_to_boolean":
schema = {"type": ["string", "boolean"]}
schema.update(**{"type": ["string", "boolean"]})
elif convert_to.__name__ == "convert_to_boolean_if_not_none":
schema = {"type": ["string", "boolean", "null"]}
schema.update(**{"type": ["string", "boolean", "null"]})
elif convert_to.__name__ == "convert_to_int":
schema = {"type": ["string", "integer"]}
schema.update(**{"type": ["string", "integer"]})
elif convert_to.__name__ == "convert_to_int_if_not_none":
schema = {"type": ["string", "integer", "null"]}
schema.update(**{"type": ["string", "integer", "null"]})
elif convert_to.__name__ == "convert_validate_port_value":
schema = {"type": ["integer", "null"]}
schema.update(**{"type": ["integer", "null"]})
else:
logging.warning(
"Unsupported conversion function %s used", convert_to.__name__