[python-experimental] move validations into cls (#13252)

* Adds null checks to validation properties

* Modifies the templates to move validations into the cls

* Regnerates unit test spec

* Template update to get rid of cls factory for validations

* Updates samples for unit test spec

* Moves SchemaValidator class

* Removes SchemaValidator

* Fixes 2 tests in v3 sample

* Reverts version files

* Reverts 2 files
This commit is contained in:
Justin Black
2022-08-22 15:34:48 -07:00
committed by GitHub
parent ff03e1ac8d
commit fac576a2bf
121 changed files with 1084 additions and 1268 deletions

View File

@@ -1,14 +1,11 @@
class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#if getIsAnyType}}
{{#if composedSchemas}}
schemas.ComposedSchema
schemas.ComposedSchema,
{{else}}
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
{{/if}}
{{else}}
{{#if getHasMultipleTypes}}
@@ -34,6 +31,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#or isMap isAnyType}}
{{> model_templates/dict_partial }}
{{/or}}

View File

@@ -1,9 +1,6 @@
class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
schemas.DictSchema
):
{{#if this.classname}}
@@ -17,6 +14,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{> model_templates/dict_partial }}

View File

@@ -1,9 +1,6 @@
class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
schemas.ListSchema
):
{{#if this.classname}}
@@ -17,6 +14,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#with items}}
{{#if complexType}}

View File

@@ -1,9 +1,6 @@
class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}(
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#if isEnum}}
{{> model_templates/enum_value_to_name }}
{{/if}}
@@ -20,6 +17,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{/if}}
"""
{{/if}}
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{#if isEnum}}
{{> model_templates/enums }}
{{else}}

View File

@@ -1,50 +1,48 @@
schemas.SchemaValidatorClsFactory(
{{#if getUniqueItems}}
unique_items=True,
_unique_items=True
{{/if}}
{{#if maxLength}}
max_length={{maxLength}},
{{/if}}
{{#if minLength}}
min_length={{minLength}},
{{/if}}
{{#if maxItems}}
max_items={{maxItems}},
{{/if}}
{{#if minItems}}
min_items={{minItems}},
{{/if}}
{{#neq maxProperties null }}
max_properties={{maxProperties}},
{{#neq maxLength null}}
_max_length={{maxLength}}
{{/neq}}
{{#if minProperties}}
min_properties={{minProperties}},
{{/if}}
{{#if maximum}}
{{#if exclusiveMaximum}}exclusive_maximum{{/if}}inclusive_maximum{{#unless exclusiveMaximum}}{{/unless}}={{maximum}},
{{/if}}
{{#if minimum}}
{{#if exclusiveMinimum}}exclusive_minimum{{/if}}inclusive_minimum{{#unless exclusiveMinimum}}{{/unless}}={{minimum}},
{{/if}}
{{#if pattern}}
regex=[{
{{#neq minLength null}}
_min_length={{minLength}}
{{/neq}}
{{#neq maxItems null}}
_max_items={{maxItems}}
{{/neq}}
{{#neq minItems null}}
_min_items={{minItems}}
{{/neq}}
{{#neq maxProperties null }}
_max_properties={{maxProperties}}
{{/neq}}
{{#neq minProperties null}}
_min_properties={{minProperties}}
{{/neq}}
{{#neq maximum null}}
_{{#if exclusiveMaximum}}exclusive_maximum{{/if}}inclusive_maximum{{#unless exclusiveMaximum}}{{/unless}}={{maximum}}
{{/neq}}
{{#neq minimum null}}
_{{#if exclusiveMinimum}}exclusive_minimum{{/if}}inclusive_minimum{{#unless exclusiveMinimum}}{{/unless}}={{minimum}}
{{/neq}}
{{#neq pattern null}}
_regex=[{
{{#if vendorExtensions.x-regex}}
'pattern': r'{{{vendorExtensions.x-regex}}}', # noqa: E501
'pattern': r'{{{vendorExtensions.x-regex}}}', # noqa: E501
{{else}}
'pattern': r'{{{pattern}}}', # noqa: E501
'pattern': r'{{{pattern}}}', # noqa: E501
{{/if}}
{{#each vendorExtensions.x-modifiers}}
{{#if @first}}
'flags': (
'flags': (
{{/if}}
{{#unless @first}}| {{/unless}}re.{{.}}
{{#unless @first}}| {{/unless}}re.{{.}}
{{#if @last}}
)
)
{{/if}}
{{/each}}
}],
{{/if}}
{{#if multipleOf}}
multiple_of={{multipleOf}},
{{/if}}
),
}]
{{/neq}}
{{#neq multipleOf null}}
_multiple_of={{multipleOf}}
{{/neq}}

View File

@@ -142,226 +142,6 @@ class ValidationMetadata(frozendict):
return self.get('validated_path_to_schemas')
class ValidatorBase:
@staticmethod
def __is_json_validation_enabled(schema_keyword, configuration=None):
"""Returns true if JSON schema validation is enabled for the specified
validation keyword. This can be used to skip JSON schema structural validation
as requested in the configuration.
Args:
schema_keyword (string): the name of a JSON schema validation keyword.
configuration (Configuration): the configuration class.
"""
return (configuration is None or
not hasattr(configuration, '_disabled_client_side_validations') or
schema_keyword not in configuration._disabled_client_side_validations)
@staticmethod
def __raise_validation_error_message(value, constraint_msg, constraint_value, path_to_item, additional_txt=""):
raise ApiValueError(
"Invalid value `{value}`, {constraint_msg} `{constraint_value}`{additional_txt} at {path_to_item}".format(
value=value,
constraint_msg=constraint_msg,
constraint_value=constraint_value,
additional_txt=additional_txt,
path_to_item=path_to_item,
)
)
@classmethod
def __check_str_validations(cls,
validations, input_values,
validation_metadata: ValidationMetadata):
if (cls.__is_json_validation_enabled('maxLength', validation_metadata.configuration) and
'max_length' in validations and
len(input_values) > validations['max_length']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="length must be less than or equal to",
constraint_value=validations['max_length'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minLength', validation_metadata.configuration) and
'min_length' in validations and
len(input_values) < validations['min_length']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="length must be greater than or equal to",
constraint_value=validations['min_length'],
path_to_item=validation_metadata.path_to_item
)
checked_value = input_values
if (cls.__is_json_validation_enabled('pattern', validation_metadata.configuration) and
'regex' in validations):
for regex_dict in validations['regex']:
flags = regex_dict.get('flags', 0)
if not re.search(regex_dict['pattern'], checked_value, flags=flags):
if flags != 0:
# Don't print the regex flags if the flags are not
# specified in the OAS document.
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item,
additional_txt=" with flags=`{}`".format(flags)
)
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def __check_tuple_validations(
cls, validations, input_values,
validation_metadata: ValidationMetadata):
if (cls.__is_json_validation_enabled('maxItems', validation_metadata.configuration) and
'max_items' in validations and
len(input_values) > validations['max_items']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of items must be less than or equal to",
constraint_value=validations['max_items'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minItems', validation_metadata.configuration) and
'min_items' in validations and
len(input_values) < validations['min_items']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of items must be greater than or equal to",
constraint_value=validations['min_items'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('uniqueItems', validation_metadata.configuration) and
'unique_items' in validations and validations['unique_items'] and input_values):
unique_items = set(input_values)
if len(input_values) > len(unique_items):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="duplicate items were found, and the tuple must not contain duplicates because",
constraint_value='unique_items==True',
path_to_item=validation_metadata.path_to_item
)
@classmethod
def __check_dict_validations(
cls, validations, input_values,
validation_metadata: ValidationMetadata):
if (cls.__is_json_validation_enabled('maxProperties', validation_metadata.configuration) and
'max_properties' in validations and
len(input_values) > validations['max_properties']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of properties must be less than or equal to",
constraint_value=validations['max_properties'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minProperties', validation_metadata.configuration) and
'min_properties' in validations and
len(input_values) < validations['min_properties']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of properties must be greater than or equal to",
constraint_value=validations['min_properties'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def __check_numeric_validations(
cls, validations, input_values,
validation_metadata: ValidationMetadata):
if cls.__is_json_validation_enabled('multipleOf',
validation_metadata.configuration) and 'multiple_of' in validations:
multiple_of_value = validations['multiple_of']
if (isinstance(input_values, decimal.Decimal) and
not (float(input_values) / multiple_of_value).is_integer()
):
# Note 'multipleOf' will be as good as the floating point arithmetic.
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="value must be a multiple of",
constraint_value=multiple_of_value,
path_to_item=validation_metadata.path_to_item
)
checking_max_or_min_values = {'exclusive_maximum', 'inclusive_maximum', 'exclusive_minimum',
'inclusive_minimum'}.isdisjoint(validations) is False
if not checking_max_or_min_values:
return
max_val = input_values
min_val = input_values
if (cls.__is_json_validation_enabled('exclusiveMaximum', validation_metadata.configuration) and
'exclusive_maximum' in validations and
max_val >= validations['exclusive_maximum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value less than",
constraint_value=validations['exclusive_maximum'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('maximum', validation_metadata.configuration) and
'inclusive_maximum' in validations and
max_val > validations['inclusive_maximum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value less than or equal to",
constraint_value=validations['inclusive_maximum'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('exclusiveMinimum', validation_metadata.configuration) and
'exclusive_minimum' in validations and
min_val <= validations['exclusive_minimum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value greater than",
constraint_value=validations['exclusive_maximum'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minimum', validation_metadata.configuration) and
'inclusive_minimum' in validations and
min_val < validations['inclusive_minimum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value greater than or equal to",
constraint_value=validations['inclusive_minimum'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _check_validations_for_types(
cls,
validations,
input_values,
validation_metadata: ValidationMetadata
):
if isinstance(input_values, str):
cls.__check_str_validations(validations, input_values, validation_metadata)
elif isinstance(input_values, tuple):
cls.__check_tuple_validations(validations, input_values, validation_metadata)
elif isinstance(input_values, frozendict):
cls.__check_dict_validations(validations, input_values, validation_metadata)
elif isinstance(input_values, decimal.Decimal):
cls.__check_numeric_validations(validations, input_values, validation_metadata)
class Singleton:
"""
Enums and singletons are the same
@@ -427,6 +207,37 @@ class BoolClass(Singleton):
raise ValueError('Unable to find the boolean value of this instance')
class ValidatorBase:
@staticmethod
def is_json_validation_enabled_oapg(schema_keyword, configuration=None):
"""Returns true if JSON schema validation is enabled for the specified
validation keyword. This can be used to skip JSON schema structural validation
as requested in the configuration.
Note: the suffix _oapg stands for openapi python (experimental) generator and
it has been added to prevent collisions with other methods and properties
Args:
schema_keyword (string): the name of a JSON schema validation keyword.
configuration (Configuration): the configuration class.
"""
return (configuration is None or
not hasattr(configuration, '_disabled_client_side_validations') or
schema_keyword not in configuration._disabled_client_side_validations)
@staticmethod
def raise_validation_error_message_oapg(value, constraint_msg, constraint_value, path_to_item, additional_txt=""):
raise ApiValueError(
"Invalid value `{value}`, {constraint_msg} `{constraint_value}`{additional_txt} at {path_to_item}".format(
value=value,
constraint_msg=constraint_msg,
constraint_value=constraint_value,
additional_txt=additional_txt,
path_to_item=path_to_item,
)
)
class Validator(typing.Protocol):
@classmethod
def _validate(
@@ -437,24 +248,6 @@ class Validator(typing.Protocol):
pass
def SchemaValidatorClsFactory(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator:
class SchemaValidator(ValidatorBase):
@classmethod
def _validate(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]:
"""
SchemaValidator _validate
Validates that validations pass
"""
cls._check_validations_for_types(validations, arg, validation_metadata)
return super()._validate(arg, validation_metadata)
return SchemaValidator
def SchemaTypeCheckerClsFactory(union_type_cls: typing.Union[typing.Any]) -> Validator:
if typing.get_origin(union_type_cls) is typing.Union:
union_classes = typing.get_args(union_type_cls)
@@ -530,7 +323,7 @@ def SchemaTypeCheckerClsFactory(union_type_cls: typing.Union[typing.Any]) -> Val
"""
arg_type = type(arg)
if arg_type in union_classes:
return super()._validate(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
raise cls._get_type_error(
arg,
validation_metadata.path_to_item,
@@ -583,7 +376,7 @@ def SchemaEnumMakerClsFactory(enum_value_to_name: typing.Dict[typing.Union[str,
cls._enum_value_to_name[arg]
except KeyError:
raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name))
return super()._validate(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
return SchemaEnumMaker
@@ -619,7 +412,7 @@ class NoneBase:
return False
class StrBase:
class StrBase(ValidatorBase):
@property
def as_str(self) -> str:
return self
@@ -640,6 +433,68 @@ class StrBase:
def as_uuid(self) -> uuid.UUID:
raise Exception('not implemented')
@classmethod
def __check_str_validations(
cls,
arg: str,
validation_metadata: ValidationMetadata
):
if (cls.is_json_validation_enabled_oapg('maxLength', validation_metadata.configuration) and
hasattr(cls, '_max_length') and
len(arg) > cls._max_length):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="length must be less than or equal to",
constraint_value=cls._max_length,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minLength', validation_metadata.configuration) and
hasattr(cls, '_min_length') and
len(arg) < cls._min_length):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="length must be greater than or equal to",
constraint_value=cls._min_length,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('pattern', validation_metadata.configuration) and
hasattr(cls, '_regex')):
for regex_dict in cls._regex:
flags = regex_dict.get('flags', 0)
if not re.search(regex_dict['pattern'], arg, flags=flags):
if flags != 0:
# Don't print the regex flags if the flags are not
# specified in the OAS document.
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item,
additional_txt=" with flags=`{}`".format(flags)
)
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]:
"""
StrBase _validate
Validates that validations pass
"""
if isinstance(arg, str):
cls.__check_str_validations(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
class UUIDBase(StrBase):
@property
@@ -806,7 +661,7 @@ class DecimalBase(StrBase):
return super()._validate(arg, validation_metadata=validation_metadata)
class NumberBase:
class NumberBase(ValidatorBase):
@property
def as_int(self) -> int:
try:
@@ -837,8 +692,91 @@ class NumberBase:
self._as_float = float(self)
return self._as_float
@classmethod
def __check_numeric_validations(
cls,
arg,
validation_metadata: ValidationMetadata
):
if cls.is_json_validation_enabled_oapg('multipleOf',
validation_metadata.configuration) and hasattr(cls, '_multiple_of'):
multiple_of_value = cls._multiple_of
if (not (float(arg) / multiple_of_value).is_integer()):
# Note 'multipleOf' will be as good as the floating point arithmetic.
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="value must be a multiple of",
constraint_value=multiple_of_value,
path_to_item=validation_metadata.path_to_item
)
class ListBase:
checking_max_or_min_values = any(
hasattr(cls, validation_key) for validation_key in {
'_exclusive_maximum',
'_inclusive_maximum',
'_exclusive_minimum',
'_inclusive_minimum',
}
)
if not checking_max_or_min_values:
return
if (cls.is_json_validation_enabled_oapg('exclusiveMaximum', validation_metadata.configuration) and
hasattr(cls, '_exclusive_maximum') and
arg >= cls._exclusive_maximum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value less than",
constraint_value=cls._exclusive_maximum,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('maximum', validation_metadata.configuration) and
hasattr(cls, '_inclusive_maximum') and
arg > cls._inclusive_maximum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value less than or equal to",
constraint_value=cls._inclusive_maximum,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('exclusiveMinimum', validation_metadata.configuration) and
hasattr(cls, '_exclusive_minimum') and
arg <= cls._exclusive_minimum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value greater than",
constraint_value=cls._exclusive_maximum,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minimum', validation_metadata.configuration) and
hasattr(cls, '_inclusive_minimum') and
arg < cls._inclusive_minimum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value greater than or equal to",
constraint_value=cls._inclusive_minimum,
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]:
"""
NumberBase _validate
Validates that validations pass
"""
if isinstance(arg, decimal.Decimal):
cls.__check_numeric_validations(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
class ListBase(ValidatorBase):
@classmethod
def _validate_items(cls, list_items, validation_metadata: ValidationMetadata):
"""
@@ -872,6 +810,42 @@ class ListBase:
update(path_to_schemas, other_path_to_schemas)
return path_to_schemas
@classmethod
def __check_tuple_validations(
cls, arg,
validation_metadata: ValidationMetadata):
if (cls.is_json_validation_enabled_oapg('maxItems', validation_metadata.configuration) and
hasattr(cls, '_max_items') and
len(arg) > cls._max_items):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of items must be less than or equal to",
constraint_value=cls._max_items,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minItems', validation_metadata.configuration) and
hasattr(cls, '_min_items') and
len(arg) < cls._min_items):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of items must be greater than or equal to",
constraint_value=cls._min_items,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('uniqueItems', validation_metadata.configuration) and
hasattr(cls, '_unique_items') and cls._unique_items and arg):
unique_items = set(arg)
if len(arg) > len(unique_items):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="duplicate items were found, and the tuple must not contain duplicates because",
constraint_value='unique_items==True',
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
@@ -893,6 +867,8 @@ class ListBase:
ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes
ApiTypeError: when the input type is not in the list of allowed spec types
"""
if isinstance(arg, tuple):
cls.__check_tuple_validations(arg, validation_metadata)
_path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata)
if not isinstance(arg, tuple):
return _path_to_schemas
@@ -987,7 +963,7 @@ class Discriminable:
return None
class DictBase(Discriminable):
class DictBase(Discriminable, ValidatorBase):
# subclass properties
_required_property_names = set()
@@ -1079,6 +1055,32 @@ class DictBase(Discriminable):
update(path_to_schemas, other_path_to_schemas)
return path_to_schemas
@classmethod
def __check_dict_validations(
cls,
arg,
validation_metadata: ValidationMetadata
):
if (cls.is_json_validation_enabled_oapg('maxProperties', validation_metadata.configuration) and
hasattr(cls, '_max_properties') and
len(arg) > cls._max_properties):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of properties must be less than or equal to",
constraint_value=cls._max_properties,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minProperties', validation_metadata.configuration) and
hasattr(cls, '_min_properties') and
len(arg) < cls._min_properties):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of properties must be greater than or equal to",
constraint_value=cls._min_properties,
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
@@ -1100,6 +1102,8 @@ class DictBase(Discriminable):
ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes
ApiTypeError: when the input type is not in the list of allowed spec types
"""
if isinstance(arg, frozendict):
cls.__check_dict_validations(arg, validation_metadata)
_path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata)
if not isinstance(arg, frozendict):
return _path_to_schemas
@@ -1836,13 +1840,9 @@ class IntSchema(IntBase, NumberSchema):
return super().__new__(cls, arg, **kwargs)
class Int32Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-2147483648),
inclusive_maximum=decimal.Decimal(2147483647)
),
):
pass
class Int32Base:
_inclusive_minimum = decimal.Decimal(-2147483648)
_inclusive_maximum = decimal.Decimal(2147483647)
class Int32Schema(
@@ -1852,13 +1852,9 @@ class Int32Schema(
pass
class Int64Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-9223372036854775808),
inclusive_maximum=decimal.Decimal(9223372036854775807)
),
):
pass
class Int64Base:
_inclusive_minimum = decimal.Decimal(-9223372036854775808)
_inclusive_maximum = decimal.Decimal(9223372036854775807)
class Int64Schema(
@@ -1868,13 +1864,9 @@ class Int64Schema(
pass
class Float32Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-3.4028234663852886e+38),
inclusive_maximum=decimal.Decimal(3.4028234663852886e+38)
),
):
pass
class Float32Base:
_inclusive_minimum = decimal.Decimal(-3.4028234663852886e+38)
_inclusive_maximum = decimal.Decimal(3.4028234663852886e+38)
class Float32Schema(
@@ -1888,13 +1880,9 @@ class Float32Schema(
return super()._from_openapi_data(arg, _configuration=_configuration)
class Float64Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-1.7976931348623157E+308),
inclusive_maximum=decimal.Decimal(1.7976931348623157E+308)
),
):
pass
class Float64Base:
_inclusive_minimum = decimal.Decimal(-1.7976931348623157E+308)
_inclusive_maximum = decimal.Decimal(1.7976931348623157E+308)
class Float64Schema(

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AdditionalpropertiesAreAllowedByDefault(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AdditionalpropertiesShouldNotLookInApplicators(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -47,7 +47,7 @@ class AdditionalpropertiesShouldNotLookInApplicators(
class all_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
foo = schemas.AnyTypeSchema

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class Allof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class Allof(
class all_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"bar",
@@ -70,7 +70,7 @@ class Allof(
class all_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofCombinedWithAnyofOneof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,11 +46,9 @@ class AllofCombinedWithAnyofOneof(
class all_of_0(
schemas.SchemaValidatorClsFactory(
multiple_of=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_multiple_of=2
def __new__(
cls,
@@ -67,11 +65,9 @@ class AllofCombinedWithAnyofOneof(
class one_of_0(
schemas.SchemaValidatorClsFactory(
multiple_of=5,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_multiple_of=5
def __new__(
cls,
@@ -88,11 +84,9 @@ class AllofCombinedWithAnyofOneof(
class any_of_0(
schemas.SchemaValidatorClsFactory(
multiple_of=3,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_multiple_of=3
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofSimpleTypes(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,11 +46,9 @@ class AllofSimpleTypes(
class all_of_0(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=30,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_inclusive_maximum=30
def __new__(
cls,
@@ -67,11 +65,9 @@ class AllofSimpleTypes(
class all_of_1(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=20,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_inclusive_minimum=20
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofWithBaseSchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -50,7 +50,7 @@ class AllofWithBaseSchema(
class all_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",
@@ -74,7 +74,7 @@ class AllofWithBaseSchema(
class all_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"baz",

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofWithOneEmptySchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofWithTheFirstEmptySchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofWithTheLastEmptySchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AllofWithTwoEmptySchemas(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class Anyof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -47,11 +47,9 @@ class Anyof(
class any_of_1(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_inclusive_minimum=2
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AnyofComplexTypes(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class AnyofComplexTypes(
class any_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"bar",
@@ -70,7 +70,7 @@ class AnyofComplexTypes(
class any_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",

View File

@@ -47,11 +47,9 @@ class AnyofWithBaseSchema(
class any_of_0(
schemas.SchemaValidatorClsFactory(
max_length=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_max_length=2
def __new__(
cls,
@@ -68,11 +66,9 @@ class AnyofWithBaseSchema(
class any_of_1(
schemas.SchemaValidatorClsFactory(
min_length=4,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_min_length=4
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class AnyofWithOneEmptySchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class ByInt(
schemas.SchemaValidatorClsFactory(
multiple_of=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_multiple_of=2
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class ByNumber(
schemas.SchemaValidatorClsFactory(
multiple_of=1.5,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_multiple_of=1.5
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class BySmallNumber(
schemas.SchemaValidatorClsFactory(
multiple_of=0.00010,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_multiple_of=0.00010
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class ForbiddenProperty(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -34,7 +34,7 @@ class ForbiddenProperty(
class foo(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -24,9 +24,6 @@ from unit_test_api import schemas # noqa: F401
class InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf(
schemas.SchemaValidatorClsFactory(
multiple_of=0.123456789,
),
schemas.IntSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -34,4 +31,5 @@ class InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf(
Do not edit the class manually.
"""
_multiple_of=0.123456789
pass

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class InvalidStringValueForDefault(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -34,11 +34,9 @@ class InvalidStringValueForDefault(
class bar(
schemas.SchemaValidatorClsFactory(
min_length=4,
),
schemas.StrSchema
):
_min_length=4
pass
def __new__(

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MaximumValidation(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=3.0,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_inclusive_maximum=3.0
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MaximumValidationWithUnsignedInteger(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=300,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_inclusive_maximum=300
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MaxitemsValidation(
schemas.SchemaValidatorClsFactory(
max_items=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_max_items=2
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MaxlengthValidation(
schemas.SchemaValidatorClsFactory(
max_length=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_max_length=2
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class Maxproperties0MeansTheObjectIsEmpty(
schemas.SchemaValidatorClsFactory(
max_properties=0,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_max_properties=0
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MaxpropertiesValidation(
schemas.SchemaValidatorClsFactory(
max_properties=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_max_properties=2
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MinimumValidation(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=1.1,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_inclusive_minimum=1.1
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MinimumValidationWithSignedInteger(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=-2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_inclusive_minimum=-2
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MinitemsValidation(
schemas.SchemaValidatorClsFactory(
min_items=1,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_min_items=1
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MinlengthValidation(
schemas.SchemaValidatorClsFactory(
min_length=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_min_length=2
def __new__(
cls,

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class MinpropertiesValidation(
schemas.SchemaValidatorClsFactory(
min_properties=1,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_min_properties=1
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class ModelNot(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class NestedAllofToCheckValidationSemantics(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class NestedAllofToCheckValidationSemantics(
class all_of_0(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class NestedAnyofToCheckValidationSemantics(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class NestedAnyofToCheckValidationSemantics(
class any_of_0(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class NestedOneofToCheckValidationSemantics(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class NestedOneofToCheckValidationSemantics(
class one_of_0(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class NotMoreComplexSchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class ObjectPropertiesValidation(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class Oneof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -47,11 +47,9 @@ class Oneof(
class one_of_1(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_inclusive_minimum=2
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class OneofComplexTypes(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -46,7 +46,7 @@ class OneofComplexTypes(
class one_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"bar",
@@ -70,7 +70,7 @@ class OneofComplexTypes(
class one_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",

View File

@@ -47,11 +47,9 @@ class OneofWithBaseSchema(
class one_of_0(
schemas.SchemaValidatorClsFactory(
min_length=2,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_min_length=2
def __new__(
cls,
@@ -68,11 +66,9 @@ class OneofWithBaseSchema(
class one_of_1(
schemas.SchemaValidatorClsFactory(
max_length=4,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_max_length=4
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class OneofWithEmptySchema(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -47,7 +47,7 @@ class OneofWithRequired(
class one_of_0(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"bar",
@@ -69,7 +69,7 @@ class OneofWithRequired(
class one_of_1(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo",

View File

@@ -24,18 +24,16 @@ from unit_test_api import schemas # noqa: F401
class PatternIsNotAnchored(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'a+', # noqa: E501
}],
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_regex=[{
'pattern': r'a+', # noqa: E501
}]
def __new__(
cls,

View File

@@ -24,18 +24,16 @@ from unit_test_api import schemas # noqa: F401
class PatternValidation(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^a*$', # noqa: E501
}],
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_regex=[{
'pattern': r'^a*$', # noqa: E501
}]
def __new__(
cls,

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class PropertiesWithEscapedCharacters(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class PropertyNamedRefThatIsNotAReference(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RefInAllof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RefInAnyof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RefInNot(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RefInOneof(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RefInProperty(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RequiredDefaultValidation(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RequiredValidation(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RequiredWithEmptyArray(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from unit_test_api import schemas # noqa: F401
class RequiredWithEscapedCharacters(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -34,11 +34,9 @@ class TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing(
class alpha(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=3,
),
schemas.NumberSchema
):
_inclusive_maximum=3
pass

View File

@@ -24,9 +24,7 @@ from unit_test_api import schemas # noqa: F401
class UniqueitemsFalseValidation(
schemas.SchemaValidatorClsFactory(
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,16 +24,14 @@ from unit_test_api import schemas # noqa: F401
class UniqueitemsValidation(
schemas.SchemaValidatorClsFactory(
unique_items=True,
),
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
_unique_items=True
def __new__(
cls,

View File

@@ -27,7 +27,7 @@ from . import path
class SchemaForRequestBodyApplicationJson(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -27,7 +27,7 @@ from . import path
class SchemaForRequestBodyApplicationJson(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -29,7 +29,7 @@ from . import path
class SchemaForRequestBodyApplicationJson(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -27,7 +27,7 @@ from . import path
class SchemaForRequestBodyApplicationJson(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo\"bar",

View File

@@ -26,7 +26,7 @@ from . import path
class SchemaFor200ResponseBodyApplicationJson(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -26,7 +26,7 @@ from . import path
class SchemaFor200ResponseBodyApplicationJson(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -28,7 +28,7 @@ from . import path
class SchemaFor200ResponseBodyApplicationJson(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod

View File

@@ -26,7 +26,7 @@ from . import path
class SchemaFor200ResponseBodyApplicationJson(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
_required_property_names = {
"foo\"bar",

View File

@@ -149,226 +149,6 @@ class ValidationMetadata(frozendict):
return self.get('validated_path_to_schemas')
class ValidatorBase:
@staticmethod
def __is_json_validation_enabled(schema_keyword, configuration=None):
"""Returns true if JSON schema validation is enabled for the specified
validation keyword. This can be used to skip JSON schema structural validation
as requested in the configuration.
Args:
schema_keyword (string): the name of a JSON schema validation keyword.
configuration (Configuration): the configuration class.
"""
return (configuration is None or
not hasattr(configuration, '_disabled_client_side_validations') or
schema_keyword not in configuration._disabled_client_side_validations)
@staticmethod
def __raise_validation_error_message(value, constraint_msg, constraint_value, path_to_item, additional_txt=""):
raise ApiValueError(
"Invalid value `{value}`, {constraint_msg} `{constraint_value}`{additional_txt} at {path_to_item}".format(
value=value,
constraint_msg=constraint_msg,
constraint_value=constraint_value,
additional_txt=additional_txt,
path_to_item=path_to_item,
)
)
@classmethod
def __check_str_validations(cls,
validations, input_values,
validation_metadata: ValidationMetadata):
if (cls.__is_json_validation_enabled('maxLength', validation_metadata.configuration) and
'max_length' in validations and
len(input_values) > validations['max_length']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="length must be less than or equal to",
constraint_value=validations['max_length'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minLength', validation_metadata.configuration) and
'min_length' in validations and
len(input_values) < validations['min_length']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="length must be greater than or equal to",
constraint_value=validations['min_length'],
path_to_item=validation_metadata.path_to_item
)
checked_value = input_values
if (cls.__is_json_validation_enabled('pattern', validation_metadata.configuration) and
'regex' in validations):
for regex_dict in validations['regex']:
flags = regex_dict.get('flags', 0)
if not re.search(regex_dict['pattern'], checked_value, flags=flags):
if flags != 0:
# Don't print the regex flags if the flags are not
# specified in the OAS document.
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item,
additional_txt=" with flags=`{}`".format(flags)
)
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def __check_tuple_validations(
cls, validations, input_values,
validation_metadata: ValidationMetadata):
if (cls.__is_json_validation_enabled('maxItems', validation_metadata.configuration) and
'max_items' in validations and
len(input_values) > validations['max_items']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of items must be less than or equal to",
constraint_value=validations['max_items'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minItems', validation_metadata.configuration) and
'min_items' in validations and
len(input_values) < validations['min_items']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of items must be greater than or equal to",
constraint_value=validations['min_items'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('uniqueItems', validation_metadata.configuration) and
'unique_items' in validations and validations['unique_items'] and input_values):
unique_items = set(input_values)
if len(input_values) > len(unique_items):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="duplicate items were found, and the tuple must not contain duplicates because",
constraint_value='unique_items==True',
path_to_item=validation_metadata.path_to_item
)
@classmethod
def __check_dict_validations(
cls, validations, input_values,
validation_metadata: ValidationMetadata):
if (cls.__is_json_validation_enabled('maxProperties', validation_metadata.configuration) and
'max_properties' in validations and
len(input_values) > validations['max_properties']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of properties must be less than or equal to",
constraint_value=validations['max_properties'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minProperties', validation_metadata.configuration) and
'min_properties' in validations and
len(input_values) < validations['min_properties']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="number of properties must be greater than or equal to",
constraint_value=validations['min_properties'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def __check_numeric_validations(
cls, validations, input_values,
validation_metadata: ValidationMetadata):
if cls.__is_json_validation_enabled('multipleOf',
validation_metadata.configuration) and 'multiple_of' in validations:
multiple_of_value = validations['multiple_of']
if (isinstance(input_values, decimal.Decimal) and
not (float(input_values) / multiple_of_value).is_integer()
):
# Note 'multipleOf' will be as good as the floating point arithmetic.
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="value must be a multiple of",
constraint_value=multiple_of_value,
path_to_item=validation_metadata.path_to_item
)
checking_max_or_min_values = {'exclusive_maximum', 'inclusive_maximum', 'exclusive_minimum',
'inclusive_minimum'}.isdisjoint(validations) is False
if not checking_max_or_min_values:
return
max_val = input_values
min_val = input_values
if (cls.__is_json_validation_enabled('exclusiveMaximum', validation_metadata.configuration) and
'exclusive_maximum' in validations and
max_val >= validations['exclusive_maximum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value less than",
constraint_value=validations['exclusive_maximum'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('maximum', validation_metadata.configuration) and
'inclusive_maximum' in validations and
max_val > validations['inclusive_maximum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value less than or equal to",
constraint_value=validations['inclusive_maximum'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('exclusiveMinimum', validation_metadata.configuration) and
'exclusive_minimum' in validations and
min_val <= validations['exclusive_minimum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value greater than",
constraint_value=validations['exclusive_maximum'],
path_to_item=validation_metadata.path_to_item
)
if (cls.__is_json_validation_enabled('minimum', validation_metadata.configuration) and
'inclusive_minimum' in validations and
min_val < validations['inclusive_minimum']):
cls.__raise_validation_error_message(
value=input_values,
constraint_msg="must be a value greater than or equal to",
constraint_value=validations['inclusive_minimum'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _check_validations_for_types(
cls,
validations,
input_values,
validation_metadata: ValidationMetadata
):
if isinstance(input_values, str):
cls.__check_str_validations(validations, input_values, validation_metadata)
elif isinstance(input_values, tuple):
cls.__check_tuple_validations(validations, input_values, validation_metadata)
elif isinstance(input_values, frozendict):
cls.__check_dict_validations(validations, input_values, validation_metadata)
elif isinstance(input_values, decimal.Decimal):
cls.__check_numeric_validations(validations, input_values, validation_metadata)
class Singleton:
"""
Enums and singletons are the same
@@ -434,6 +214,37 @@ class BoolClass(Singleton):
raise ValueError('Unable to find the boolean value of this instance')
class ValidatorBase:
@staticmethod
def is_json_validation_enabled_oapg(schema_keyword, configuration=None):
"""Returns true if JSON schema validation is enabled for the specified
validation keyword. This can be used to skip JSON schema structural validation
as requested in the configuration.
Note: the suffix _oapg stands for openapi python (experimental) generator and
it has been added to prevent collisions with other methods and properties
Args:
schema_keyword (string): the name of a JSON schema validation keyword.
configuration (Configuration): the configuration class.
"""
return (configuration is None or
not hasattr(configuration, '_disabled_client_side_validations') or
schema_keyword not in configuration._disabled_client_side_validations)
@staticmethod
def raise_validation_error_message_oapg(value, constraint_msg, constraint_value, path_to_item, additional_txt=""):
raise ApiValueError(
"Invalid value `{value}`, {constraint_msg} `{constraint_value}`{additional_txt} at {path_to_item}".format(
value=value,
constraint_msg=constraint_msg,
constraint_value=constraint_value,
additional_txt=additional_txt,
path_to_item=path_to_item,
)
)
class Validator(typing.Protocol):
@classmethod
def _validate(
@@ -444,24 +255,6 @@ class Validator(typing.Protocol):
pass
def SchemaValidatorClsFactory(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator:
class SchemaValidator(ValidatorBase):
@classmethod
def _validate(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]:
"""
SchemaValidator _validate
Validates that validations pass
"""
cls._check_validations_for_types(validations, arg, validation_metadata)
return super()._validate(arg, validation_metadata)
return SchemaValidator
def SchemaTypeCheckerClsFactory(union_type_cls: typing.Union[typing.Any]) -> Validator:
if typing.get_origin(union_type_cls) is typing.Union:
union_classes = typing.get_args(union_type_cls)
@@ -537,7 +330,7 @@ def SchemaTypeCheckerClsFactory(union_type_cls: typing.Union[typing.Any]) -> Val
"""
arg_type = type(arg)
if arg_type in union_classes:
return super()._validate(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
raise cls._get_type_error(
arg,
validation_metadata.path_to_item,
@@ -590,7 +383,7 @@ def SchemaEnumMakerClsFactory(enum_value_to_name: typing.Dict[typing.Union[str,
cls._enum_value_to_name[arg]
except KeyError:
raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name))
return super()._validate(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
return SchemaEnumMaker
@@ -626,7 +419,7 @@ class NoneBase:
return False
class StrBase:
class StrBase(ValidatorBase):
@property
def as_str(self) -> str:
return self
@@ -647,6 +440,68 @@ class StrBase:
def as_uuid(self) -> uuid.UUID:
raise Exception('not implemented')
@classmethod
def __check_str_validations(
cls,
arg: str,
validation_metadata: ValidationMetadata
):
if (cls.is_json_validation_enabled_oapg('maxLength', validation_metadata.configuration) and
hasattr(cls, '_max_length') and
len(arg) > cls._max_length):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="length must be less than or equal to",
constraint_value=cls._max_length,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minLength', validation_metadata.configuration) and
hasattr(cls, '_min_length') and
len(arg) < cls._min_length):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="length must be greater than or equal to",
constraint_value=cls._min_length,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('pattern', validation_metadata.configuration) and
hasattr(cls, '_regex')):
for regex_dict in cls._regex:
flags = regex_dict.get('flags', 0)
if not re.search(regex_dict['pattern'], arg, flags=flags):
if flags != 0:
# Don't print the regex flags if the flags are not
# specified in the OAS document.
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item,
additional_txt=" with flags=`{}`".format(flags)
)
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must match regular expression",
constraint_value=regex_dict['pattern'],
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]:
"""
StrBase _validate
Validates that validations pass
"""
if isinstance(arg, str):
cls.__check_str_validations(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
class UUIDBase(StrBase):
@property
@@ -813,7 +668,7 @@ class DecimalBase(StrBase):
return super()._validate(arg, validation_metadata=validation_metadata)
class NumberBase:
class NumberBase(ValidatorBase):
@property
def as_int(self) -> int:
try:
@@ -844,8 +699,91 @@ class NumberBase:
self._as_float = float(self)
return self._as_float
@classmethod
def __check_numeric_validations(
cls,
arg,
validation_metadata: ValidationMetadata
):
if cls.is_json_validation_enabled_oapg('multipleOf',
validation_metadata.configuration) and hasattr(cls, '_multiple_of'):
multiple_of_value = cls._multiple_of
if (not (float(arg) / multiple_of_value).is_integer()):
# Note 'multipleOf' will be as good as the floating point arithmetic.
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="value must be a multiple of",
constraint_value=multiple_of_value,
path_to_item=validation_metadata.path_to_item
)
class ListBase:
checking_max_or_min_values = any(
hasattr(cls, validation_key) for validation_key in {
'_exclusive_maximum',
'_inclusive_maximum',
'_exclusive_minimum',
'_inclusive_minimum',
}
)
if not checking_max_or_min_values:
return
if (cls.is_json_validation_enabled_oapg('exclusiveMaximum', validation_metadata.configuration) and
hasattr(cls, '_exclusive_maximum') and
arg >= cls._exclusive_maximum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value less than",
constraint_value=cls._exclusive_maximum,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('maximum', validation_metadata.configuration) and
hasattr(cls, '_inclusive_maximum') and
arg > cls._inclusive_maximum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value less than or equal to",
constraint_value=cls._inclusive_maximum,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('exclusiveMinimum', validation_metadata.configuration) and
hasattr(cls, '_exclusive_minimum') and
arg <= cls._exclusive_minimum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value greater than",
constraint_value=cls._exclusive_maximum,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minimum', validation_metadata.configuration) and
hasattr(cls, '_inclusive_minimum') and
arg < cls._inclusive_minimum):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="must be a value greater than or equal to",
constraint_value=cls._inclusive_minimum,
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]:
"""
NumberBase _validate
Validates that validations pass
"""
if isinstance(arg, decimal.Decimal):
cls.__check_numeric_validations(arg, validation_metadata)
return super()._validate(arg, validation_metadata=validation_metadata)
class ListBase(ValidatorBase):
@classmethod
def _validate_items(cls, list_items, validation_metadata: ValidationMetadata):
"""
@@ -879,6 +817,42 @@ class ListBase:
update(path_to_schemas, other_path_to_schemas)
return path_to_schemas
@classmethod
def __check_tuple_validations(
cls, arg,
validation_metadata: ValidationMetadata):
if (cls.is_json_validation_enabled_oapg('maxItems', validation_metadata.configuration) and
hasattr(cls, '_max_items') and
len(arg) > cls._max_items):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of items must be less than or equal to",
constraint_value=cls._max_items,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minItems', validation_metadata.configuration) and
hasattr(cls, '_min_items') and
len(arg) < cls._min_items):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of items must be greater than or equal to",
constraint_value=cls._min_items,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('uniqueItems', validation_metadata.configuration) and
hasattr(cls, '_unique_items') and cls._unique_items and arg):
unique_items = set(arg)
if len(arg) > len(unique_items):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="duplicate items were found, and the tuple must not contain duplicates because",
constraint_value='unique_items==True',
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
@@ -900,6 +874,8 @@ class ListBase:
ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes
ApiTypeError: when the input type is not in the list of allowed spec types
"""
if isinstance(arg, tuple):
cls.__check_tuple_validations(arg, validation_metadata)
_path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata)
if not isinstance(arg, tuple):
return _path_to_schemas
@@ -994,7 +970,7 @@ class Discriminable:
return None
class DictBase(Discriminable):
class DictBase(Discriminable, ValidatorBase):
# subclass properties
_required_property_names = set()
@@ -1086,6 +1062,32 @@ class DictBase(Discriminable):
update(path_to_schemas, other_path_to_schemas)
return path_to_schemas
@classmethod
def __check_dict_validations(
cls,
arg,
validation_metadata: ValidationMetadata
):
if (cls.is_json_validation_enabled_oapg('maxProperties', validation_metadata.configuration) and
hasattr(cls, '_max_properties') and
len(arg) > cls._max_properties):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of properties must be less than or equal to",
constraint_value=cls._max_properties,
path_to_item=validation_metadata.path_to_item
)
if (cls.is_json_validation_enabled_oapg('minProperties', validation_metadata.configuration) and
hasattr(cls, '_min_properties') and
len(arg) < cls._min_properties):
cls.raise_validation_error_message_oapg(
value=arg,
constraint_msg="number of properties must be greater than or equal to",
constraint_value=cls._min_properties,
path_to_item=validation_metadata.path_to_item
)
@classmethod
def _validate(
cls,
@@ -1107,6 +1109,8 @@ class DictBase(Discriminable):
ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes
ApiTypeError: when the input type is not in the list of allowed spec types
"""
if isinstance(arg, frozendict):
cls.__check_dict_validations(arg, validation_metadata)
_path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata)
if not isinstance(arg, frozendict):
return _path_to_schemas
@@ -1843,13 +1847,9 @@ class IntSchema(IntBase, NumberSchema):
return super().__new__(cls, arg, **kwargs)
class Int32Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-2147483648),
inclusive_maximum=decimal.Decimal(2147483647)
),
):
pass
class Int32Base:
_inclusive_minimum = decimal.Decimal(-2147483648)
_inclusive_maximum = decimal.Decimal(2147483647)
class Int32Schema(
@@ -1859,13 +1859,9 @@ class Int32Schema(
pass
class Int64Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-9223372036854775808),
inclusive_maximum=decimal.Decimal(9223372036854775807)
),
):
pass
class Int64Base:
_inclusive_minimum = decimal.Decimal(-9223372036854775808)
_inclusive_maximum = decimal.Decimal(9223372036854775807)
class Int64Schema(
@@ -1875,13 +1871,9 @@ class Int64Schema(
pass
class Float32Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-3.4028234663852886e+38),
inclusive_maximum=decimal.Decimal(3.4028234663852886e+38)
),
):
pass
class Float32Base:
_inclusive_minimum = decimal.Decimal(-3.4028234663852886e+38)
_inclusive_maximum = decimal.Decimal(3.4028234663852886e+38)
class Float32Schema(
@@ -1895,13 +1887,9 @@ class Float32Schema(
return super()._from_openapi_data(arg, _configuration=_configuration)
class Float64Base(
SchemaValidatorClsFactory(
inclusive_minimum=decimal.Decimal(-1.7976931348623157E+308),
inclusive_maximum=decimal.Decimal(1.7976931348623157E+308)
),
):
pass
class Float64Base:
_inclusive_minimum = decimal.Decimal(-1.7976931348623157E+308)
_inclusive_maximum = decimal.Decimal(1.7976931348623157E+308)
class Float64Schema(

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class AnyTypeNotString(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -40,27 +40,23 @@ class Apple(
class cultivar(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^[a-zA-Z\s]*$', # noqa: E501
}],
),
schemas.StrSchema
):
_regex=[{
'pattern': r'^[a-zA-Z\s]*$', # noqa: E501
}]
pass
class origin(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^[A-Z\s]*$', # noqa: E501
'flags': (
re.IGNORECASE
)
}],
),
schemas.StrSchema
):
_regex=[{
'pattern': r'^[A-Z\s]*$', # noqa: E501
'flags': (
re.IGNORECASE
)
}]
pass
def __new__(

View File

@@ -24,9 +24,6 @@ from petstore_api import schemas # noqa: F401
class ArrayWithValidationsInItems(
schemas.SchemaValidatorClsFactory(
max_items=2,
),
schemas.ListSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -34,12 +31,11 @@ class ArrayWithValidationsInItems(
Do not edit the class manually.
"""
_max_items=2
class _items(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=7,
),
schemas.Int64Schema
):
_inclusive_maximum=7
pass

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class Cat(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class ChildCat(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class ClassModel(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class ComplexQuadrilateral(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class ComposedAnyOfDifferentTypesNoValidations(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class ComposedOneOfDifferentTypes(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
@@ -50,12 +50,10 @@ class ComposedOneOfDifferentTypes(
class one_of_4(
schemas.SchemaValidatorClsFactory(
max_properties=4,
min_properties=4,
),
schemas.DictSchema
):
_max_properties=4
_min_properties=4
def __new__(
@@ -73,23 +71,19 @@ class ComposedOneOfDifferentTypes(
class one_of_5(
schemas.SchemaValidatorClsFactory(
max_items=4,
min_items=4,
),
schemas.ListSchema
):
_max_items=4
_min_items=4
_items = schemas.AnyTypeSchema
class one_of_6(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^2020.*', # noqa: E501
}],
),
schemas.DateTimeSchema
):
_regex=[{
'pattern': r'^2020.*', # noqa: E501
}]
pass
return {
'allOf': [

View File

@@ -24,11 +24,6 @@ from petstore_api import schemas # noqa: F401
class DateTimeWithValidations(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^2020.*', # noqa: E501
}],
),
schemas.DateTimeSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -36,4 +31,7 @@ class DateTimeWithValidations(
Do not edit the class manually.
"""
_regex=[{
'pattern': r'^2020.*', # noqa: E501
}]
pass

View File

@@ -24,11 +24,6 @@ from petstore_api import schemas # noqa: F401
class DateWithValidations(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^2020.*', # noqa: E501
}],
),
schemas.DateSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -36,4 +31,7 @@ class DateWithValidations(
Do not edit the class manually.
"""
_regex=[{
'pattern': r'^2020.*', # noqa: E501
}]
pass

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class Dog(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class EquilateralTriangle(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -40,46 +40,38 @@ class FormatTest(
class integer(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=100,
inclusive_minimum=10,
multiple_of=2,
),
schemas.IntSchema
):
_inclusive_maximum=100
_inclusive_minimum=10
_multiple_of=2
pass
int32 = schemas.Int32Schema
class int32withValidations(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=200,
inclusive_minimum=20,
),
schemas.Int32Schema
):
_inclusive_maximum=200
_inclusive_minimum=20
pass
int64 = schemas.Int64Schema
class number(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=543.2,
inclusive_minimum=32.1,
multiple_of=32.5,
),
schemas.NumberSchema
):
_inclusive_maximum=543.2
_inclusive_minimum=32.1
_multiple_of=32.5
pass
class _float(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=987.6,
inclusive_minimum=54.3,
),
schemas.Float32Schema
):
_inclusive_maximum=987.6
_inclusive_minimum=54.3
pass
locals()["float"] = _float
del locals()['_float']
@@ -97,36 +89,30 @@ class FormatTest(
class double(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=123.4,
inclusive_minimum=67.8,
),
schemas.Float64Schema
):
_inclusive_maximum=123.4
_inclusive_minimum=67.8
pass
float64 = schemas.Float64Schema
class arrayWithUniqueItems(
schemas.SchemaValidatorClsFactory(
unique_items=True,
),
schemas.ListSchema
):
_unique_items=True
_items = schemas.NumberSchema
class string(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'[a-z]', # noqa: E501
'flags': (
re.IGNORECASE
)
}],
),
schemas.StrSchema
):
_regex=[{
'pattern': r'[a-z]', # noqa: E501
'flags': (
re.IGNORECASE
)
}]
pass
byte = schemas.StrSchema
binary = schemas.BinarySchema
@@ -137,37 +123,31 @@ class FormatTest(
class password(
schemas.SchemaValidatorClsFactory(
max_length=64,
min_length=10,
),
schemas.StrSchema
):
_max_length=64
_min_length=10
pass
class pattern_with_digits(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^\d{10}$', # noqa: E501
}],
),
schemas.StrSchema
):
_regex=[{
'pattern': r'^\d{10}$', # noqa: E501
}]
pass
class pattern_with_digits_and_delimiter(
schemas.SchemaValidatorClsFactory(
regex=[{
'pattern': r'^image_\d{1,3}$', # noqa: E501
'flags': (
re.IGNORECASE
)
}],
),
schemas.StrSchema
):
_regex=[{
'pattern': r'^image_\d{1,3}$', # noqa: E501
'flags': (
re.IGNORECASE
)
}]
pass
noneProp = schemas.NoneSchema

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class Fruit(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class FruitReq(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class GmFruit(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,9 +24,6 @@ from petstore_api import schemas # noqa: F401
class IntegerMax10(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=10,
),
schemas.Int64Schema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -34,4 +31,5 @@ class IntegerMax10(
Do not edit the class manually.
"""
_inclusive_maximum=10
pass

View File

@@ -24,9 +24,6 @@ from petstore_api import schemas # noqa: F401
class IntegerMin15(
schemas.SchemaValidatorClsFactory(
inclusive_minimum=15,
),
schemas.Int64Schema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -34,4 +31,5 @@ class IntegerMin15(
Do not edit the class manually.
"""
_inclusive_minimum=15
pass

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class IsoscelesTriangle(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class Mammal(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class Model200Response(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class ModelReturn(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class Name(
schemas.AnyTypeSchema
schemas.AnyTypeSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,7 +24,7 @@ from petstore_api import schemas # noqa: F401
class NullableShape(
schemas.ComposedSchema
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

View File

@@ -24,10 +24,6 @@ from petstore_api import schemas # noqa: F401
class NumberWithValidations(
schemas.SchemaValidatorClsFactory(
inclusive_maximum=20,
inclusive_minimum=10,
),
schemas.NumberSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
@@ -35,4 +31,6 @@ class NumberWithValidations(
Do not edit the class manually.
"""
_inclusive_maximum=20
_inclusive_minimum=10
pass

View File

@@ -34,7 +34,7 @@ class ObjectWithInlineCompositionProperty(
class someProp(
schemas.ComposedSchema
schemas.ComposedSchema,
):
@classmethod
@@ -51,11 +51,9 @@ class ObjectWithInlineCompositionProperty(
class all_of_0(
schemas.SchemaValidatorClsFactory(
min_length=1,
),
schemas.StrSchema
):
_min_length=1
pass
return {
'allOf': [

Some files were not shown because too many files have changed in this diff Show More