[python-experimental] simplifies type checking (#13437)

* Better control of when to write MetaOapg

* Makes MetaOapg in Schema a type hint rather than assignmnet

* Samples regenerated

* Adds tuple types

* Removes types info

* Adds _types

* Samples regenerated

* Adds missing mixins, samples regenerated

* SchemaTypeChecker removed

* Samples regnerated
This commit is contained in:
Justin Black 2022-09-15 17:17:39 -07:00 committed by GitHub
parent 3177277b52
commit 048af8eeae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
222 changed files with 888 additions and 639 deletions

View File

@ -25,6 +25,7 @@ def discriminator(cls):
{{/with}}
{{/if}}
{{#if vars}}
class properties:
{{#each vars}}
{{#if complexType}}

View File

@ -0,0 +1,11 @@
{{#with items}}
{{#if complexType}}
@classmethod
@property
def {{baseName}}(cls) -> typing.Type['{{complexType}}']:
return {{complexType}}
{{else}}
{{> model_templates/schema }}
{{/if}}
{{/with}}

View File

@ -11,9 +11,6 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
schemas.AnyTypeSchema,
{{/if}}
{{else}}
{{#if getHasMultipleTypes}}
schemas.SchemaTypeCheckerClsFactory(typing.Union[{{#if isNull}}schemas.NoneClass, {{/if}}{{#if isMap}}frozendict.frozendict, {{/if}}{{#if isArray}}tuple, {{/if}}{{#if isString }}str, {{/if}}{{#or isInteger isNumber}}decimal.Decimal, {{/or}}{{#if isBoolean}}schemas.BoolClass, {{/if}}]),
{{/if}}
{{#if composedSchemas}}
schemas.ComposedBase,
{{/if}}
@ -41,17 +38,9 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}
{{#if getFormat}}
format = '{{getFormat}}'
{{/if}}
{{#with items}}
{{#if complexType}}
@classmethod
@property
def {{baseName}}(cls) -> typing.Type['{{complexType}}']:
return {{complexType}}
{{else}}
{{> model_templates/schema }}
{{#if getItems}}
{{> model_templates/list_partial }}
{{/if}}
{{/with}}
{{#or additionalProperties getRequiredVarsMap getHasDiscriminatorWithNonEmptyMapping vars}}
{{> model_templates/dict_partial }}
{{/or}}

View File

@ -14,13 +14,22 @@ class {{> model_templates/classname }}(
{{/if}}
"""
{{/if}}
{{#if isStub}}
{{#or additionalProperties getRequiredVarsMap getHasDiscriminatorWithNonEmptyMapping vars}}
class MetaOapg:
{{> model_templates/dict_partial }}
{{/or}}
{{else}}
{{#or additionalProperties getRequiredVarsMap getHasDiscriminatorWithNonEmptyMapping vars hasValidation}}
class MetaOapg:
{{> model_templates/dict_partial }}
{{#unless isStub}}
{{> model_templates/validations }}
{{/unless}}
{{/or}}
{{/if}}
{{> model_templates/property_type_hints }}
{{> model_templates/new }}

View File

@ -14,23 +14,24 @@ class {{> model_templates/classname }}(
{{/if}}
"""
{{/if}}
{{#if isStub}}
{{#if items}}
class MetaOapg:
{{#unless isStub}}
{{> model_templates/validations }}
{{/unless}}
{{#with items}}
{{#if complexType}}
@classmethod
@property
def {{baseName}}(cls) -> typing.Type['{{complexType}}']:
return {{complexType}}
{{else}}
{{> model_templates/schema }}
{{> model_templates/list_partial }}
{{/if}}
{{else}}
{{#or getItems hasValidation}}
class MetaOapg:
{{#if hasValidation}}
{{> model_templates/validations }}
{{/if}}
{{> model_templates/list_partial }}
{{/or}}
{{/if}}
{{/with}}
{{> model_templates/new }}

View File

@ -236,8 +236,60 @@ class Schema:
the base class of all swagger/openapi schemas/models
"""
__inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict.frozendict, FileIO, bytes, BoolClass, NoneClass}
_types: typing.Set[typing.Type]
MetaOapg = MetaOapgTyped
@staticmethod
def __get_valid_classes_phrase(input_classes):
"""Returns a string phrase describing what types are allowed"""
all_classes = list(input_classes)
all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
all_class_names = [cls.__name__ for cls in all_classes]
if len(all_class_names) == 1:
return "is {0}".format(all_class_names[0])
return "is one of [{0}]".format(", ".join(all_class_names))
@classmethod
def __type_error_message(
cls, var_value=None, var_name=None, valid_classes=None, key_type=None
):
"""
Keyword Args:
var_value (any): the variable which has the type_error
var_name (str): the name of the variable which has the typ error
valid_classes (tuple): the accepted classes for current_item's
value
key_type (bool): False if our value is a value in a dict
True if it is a key in a dict
False if our item is an item in a tuple
"""
key_or_value = "value"
if key_type:
key_or_value = "key"
valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes)
msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format(
var_name,
key_or_value,
valid_classes_phrase,
type(var_value).__name__,
)
return msg
@classmethod
def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False):
error_msg = cls.__type_error_message(
var_name=path_to_item[-1],
var_value=var_value,
valid_classes=valid_classes,
key_type=key_type,
)
return ApiTypeError(
error_msg,
path_to_item=path_to_item,
valid_classes=valid_classes,
key_type=key_type,
)
@classmethod
def _validate_oapg(
cls,
@ -246,21 +298,8 @@ class Schema:
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict.frozendict, tuple]]]:
"""
Schema _validate_oapg
Runs all schema validation logic and
returns a dynamic class of different bases depending upon the input
This makes it so:
- the returned instance is always a subclass of our defining schema
- this allows us to check type based on whether an instance is a subclass of a schema
- the returned instance is a serializable type (except for None, True, and False) which are enums
Use cases:
1. inheritable type: string/decimal.Decimal/frozendict.frozendict/tuple
2. singletons: bool/None -> uses the base classes BoolClass/NoneClass
Required Steps:
1. verify type of input is valid vs the allowed _types
2. check validations that are applicable for this type of input
3. if enums exist, check that the value exists in the enum
All keyword validation except for type checking was done in calling stack frames
If those validations passed, the validated classes are collected in path_to_schemas
Returns:
path_to_schemas: a map of path to schemas
@ -270,6 +309,14 @@ class Schema:
ApiTypeError: when the input type is not in the list of allowed spec types
"""
base_class = type(arg)
if base_class not in cls._types:
raise cls.__get_type_error(
arg,
validation_metadata.path_to_item,
cls._types,
key_type=False,
)
path_to_schemas = {validation_metadata.path_to_item: set()}
path_to_schemas[validation_metadata.path_to_item].add(cls)
path_to_schemas[validation_metadata.path_to_item].add(base_class)
@ -508,6 +555,8 @@ if typing.TYPE_CHECKING:
StrMixin = str
DecimalMixin = decimal.Decimal
BoolMixin = BoolClass
BytesMixin = bytes
FileMixin = FileIO
# qty 2
class BinaryMixin(bytes, FileIO):
pass
@ -629,77 +678,151 @@ if typing.TYPE_CHECKING:
# qty 6
class NoneFrozenDictTupleStrDecimalBoolMixin(NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass):
pass
# qty 8
class NoneFrozenDictTupleStrDecimalBoolFileBytesMixin(NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass, FileIO, bytes):
pass
else:
# qty 1
NoneMixin = object
FrozenDictMixin = object
TupleMixin = object
StrMixin = object
DecimalMixin = object
BoolMixin = object
class NoneMixin:
_types = {NoneClass}
class FrozenDictMixin:
_types = {frozendict.frozendict}
class TupleMixin:
_types = {tuple}
class StrMixin:
_types = {str}
class DecimalMixin:
_types = {decimal.Decimal}
class BoolMixin:
_types = {BoolClass}
class BytesMixin:
_types = {bytes}
class FileMixin:
_types = {FileIO}
# qty 2
BinaryMixin = object
NoneFrozenDictMixin = object
NoneTupleMixin = object
NoneStrMixin = object
NoneDecimalMixin = object
NoneBoolMixin = object
FrozenDictTupleMixin = object
FrozenDictStrMixin = object
FrozenDictDecimalMixin = object
FrozenDictBoolMixin = object
TupleStrMixin = object
TupleDecimalMixin = object
TupleBoolMixin = object
StrDecimalMixin = object
StrBoolMixin = object
DecimalBoolMixin = object
class BinaryMixin:
_types = {bytes, FileIO}
class NoneFrozenDictMixin:
_types = {NoneClass, frozendict.frozendict}
class NoneTupleMixin:
_types = {NoneClass, tuple}
class NoneStrMixin:
_types = {NoneClass, str}
class NoneDecimalMixin:
_types = {NoneClass, decimal.Decimal}
class NoneBoolMixin:
_types = {NoneClass, BoolClass}
class FrozenDictTupleMixin:
_types = {frozendict.frozendict, tuple}
class FrozenDictStrMixin:
_types = {frozendict.frozendict, str}
class FrozenDictDecimalMixin:
_types = {frozendict.frozendict, decimal.Decimal}
class FrozenDictBoolMixin:
_types = {frozendict.frozendict, BoolClass}
class TupleStrMixin:
_types = {tuple, str}
class TupleDecimalMixin:
_types = {tuple, decimal.Decimal}
class TupleBoolMixin:
_types = {tuple, BoolClass}
class StrDecimalMixin:
_types = {str, decimal.Decimal}
class StrBoolMixin:
_types = {str, BoolClass}
class DecimalBoolMixin:
_types = {decimal.Decimal, BoolClass}
# qty 3
NoneFrozenDictTupleMixin = object
NoneFrozenDictStrMixin = object
NoneFrozenDictDecimalMixin = object
NoneFrozenDictBoolMixin = object
NoneTupleStrMixin = object
NoneTupleDecimalMixin = object
NoneTupleBoolMixin = object
NoneStrDecimalMixin = object
NoneStrBoolMixin = object
NoneDecimalBoolMixin = object
FrozenDictTupleStrMixin = object
FrozenDictTupleDecimalMixin = object
FrozenDictTupleBoolMixin = object
FrozenDictStrDecimalMixin = object
FrozenDictStrBoolMixin = object
FrozenDictDecimalBoolMixin = object
TupleStrDecimalMixin = object
TupleStrBoolMixin = object
TupleDecimalBoolMixin = object
StrDecimalBoolMixin = object
class NoneFrozenDictTupleMixin:
_types = {NoneClass, frozendict.frozendict, tuple}
class NoneFrozenDictStrMixin:
_types = {NoneClass, frozendict.frozendict, str}
class NoneFrozenDictDecimalMixin:
_types = {NoneClass, frozendict.frozendict, decimal.Decimal}
class NoneFrozenDictBoolMixin:
_types = {NoneClass, frozendict.frozendict, BoolClass}
class NoneTupleStrMixin:
_types = {NoneClass, tuple, str}
class NoneTupleDecimalMixin:
_types = {NoneClass, tuple, decimal.Decimal}
class NoneTupleBoolMixin:
_types = {NoneClass, tuple, BoolClass}
class NoneStrDecimalMixin:
_types = {NoneClass, str, decimal.Decimal}
class NoneStrBoolMixin:
_types = {NoneClass, str, BoolClass}
class NoneDecimalBoolMixin:
_types = {NoneClass, decimal.Decimal, BoolClass}
class FrozenDictTupleStrMixin:
_types = {frozendict.frozendict, tuple, str}
class FrozenDictTupleDecimalMixin:
_types = {frozendict.frozendict, tuple, decimal.Decimal}
class FrozenDictTupleBoolMixin:
_types = {frozendict.frozendict, tuple, BoolClass}
class FrozenDictStrDecimalMixin:
_types = {frozendict.frozendict, str, decimal.Decimal}
class FrozenDictStrBoolMixin:
_types = {frozendict.frozendict, str, BoolClass}
class FrozenDictDecimalBoolMixin:
_types = {frozendict.frozendict, decimal.Decimal, BoolClass}
class TupleStrDecimalMixin:
_types = {tuple, str, decimal.Decimal}
class TupleStrBoolMixin:
_types = {tuple, str, BoolClass}
class TupleDecimalBoolMixin:
_types = {tuple, decimal.Decimal, BoolClass}
class StrDecimalBoolMixin:
_types = {str, decimal.Decimal, BoolClass}
# qty 4
NoneFrozenDictTupleStrMixin = object
NoneFrozenDictTupleDecimalMixin = object
NoneFrozenDictTupleBoolMixin = object
NoneFrozenDictStrDecimalMixin = object
NoneFrozenDictStrBoolMixin = object
NoneFrozenDictDecimalBoolMixin = object
NoneTupleStrDecimalMixin = object
NoneTupleStrBoolMixin = object
NoneTupleDecimalBoolMixin = object
NoneStrDecimalBoolMixin = object
FrozenDictTupleStrDecimalMixin = object
FrozenDictTupleStrBoolMixin = object
FrozenDictTupleDecimalBoolMixin = object
FrozenDictStrDecimalBoolMixin = object
TupleStrDecimalBoolMixin = object
class NoneFrozenDictTupleStrMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str}
class NoneFrozenDictTupleDecimalMixin:
_types = {NoneClass, frozendict.frozendict, tuple, decimal.Decimal}
class NoneFrozenDictTupleBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, BoolClass}
class NoneFrozenDictStrDecimalMixin:
_types = {NoneClass, frozendict.frozendict, str, decimal.Decimal}
class NoneFrozenDictStrBoolMixin:
_types = {NoneClass, frozendict.frozendict, str, BoolClass}
class NoneFrozenDictDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, decimal.Decimal, BoolClass}
class NoneTupleStrDecimalMixin:
_types = {NoneClass, tuple, str, decimal.Decimal}
class NoneTupleStrBoolMixin:
_types = {NoneClass, tuple, str, BoolClass}
class NoneTupleDecimalBoolMixin:
_types = {NoneClass, tuple, decimal.Decimal, BoolClass}
class NoneStrDecimalBoolMixin:
_types = {NoneClass, str, decimal.Decimal, BoolClass}
class FrozenDictTupleStrDecimalMixin:
_types = {frozendict.frozendict, tuple, str, decimal.Decimal}
class FrozenDictTupleStrBoolMixin:
_types = {frozendict.frozendict, tuple, str, BoolClass}
class FrozenDictTupleDecimalBoolMixin:
_types = {frozendict.frozendict, tuple, decimal.Decimal, BoolClass}
class FrozenDictStrDecimalBoolMixin:
_types = {frozendict.frozendict, str, decimal.Decimal, BoolClass}
class TupleStrDecimalBoolMixin:
_types = {tuple, str, decimal.Decimal, BoolClass}
# qty 5
NoneFrozenDictTupleStrDecimalMixin = object
NoneFrozenDictTupleStrBoolMixin = object
NoneFrozenDictTupleDecimalBoolMixin = object
NoneFrozenDictStrDecimalBoolMixin = object
NoneTupleStrDecimalBoolMixin = object
FrozenDictTupleStrDecimalBoolMixin = object
class NoneFrozenDictTupleStrDecimalMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal}
class NoneFrozenDictTupleStrBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, BoolClass}
class NoneFrozenDictTupleDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, decimal.Decimal, BoolClass}
class NoneFrozenDictStrDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, str, decimal.Decimal, BoolClass}
class NoneTupleStrDecimalBoolMixin:
_types = {NoneClass, tuple, str, decimal.Decimal, BoolClass}
class FrozenDictTupleStrDecimalBoolMixin:
_types = {frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass}
# qty 6
NoneFrozenDictTupleStrDecimalBoolMixin = object
class NoneFrozenDictTupleStrDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass}
# qty 8
class NoneFrozenDictTupleStrDecimalBoolFileBytesMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass, FileIO, bytes}
class ValidatorBase:
@ -743,92 +866,6 @@ class Validator(typing.Protocol):
pass
def SchemaTypeCheckerClsFactory(union_type_cls: typing.Any) -> Validator:
if typing.get_origin(union_type_cls) is typing.Union:
union_classes = typing.get_args(union_type_cls)
else:
# note: when a union of a single class is passed in, the union disappears
union_classes = tuple([union_type_cls])
"""
I want the type hint... union_type_cls
and to use it as a base class but when I do, I get
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
"""
class SchemaTypeChecker:
@staticmethod
def __get_valid_classes_phrase(input_classes):
"""Returns a string phrase describing what types are allowed"""
all_classes = list(input_classes)
all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
all_class_names = [cls.__name__ for cls in all_classes]
if len(all_class_names) == 1:
return "is {0}".format(all_class_names[0])
return "is one of [{0}]".format(", ".join(all_class_names))
@classmethod
def __type_error_message(
cls, var_value=None, var_name=None, valid_classes=None, key_type=None
):
"""
Keyword Args:
var_value (any): the variable which has the type_error
var_name (str): the name of the variable which has the typ error
valid_classes (tuple): the accepted classes for current_item's
value
key_type (bool): False if our value is a value in a dict
True if it is a key in a dict
False if our item is an item in a tuple
"""
key_or_value = "value"
if key_type:
key_or_value = "key"
valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes)
msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format(
var_name,
key_or_value,
valid_classes_phrase,
type(var_value).__name__,
)
return msg
@classmethod
def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False):
error_msg = cls.__type_error_message(
var_name=path_to_item[-1],
var_value=var_value,
valid_classes=valid_classes,
key_type=key_type,
)
return ApiTypeError(
error_msg,
path_to_item=path_to_item,
valid_classes=valid_classes,
key_type=key_type,
)
@classmethod
def _validate_oapg(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict.frozendict, tuple]]]:
"""
SchemaTypeChecker _validate_oapg
Validates arg's type
"""
arg_type = type(arg)
if arg_type in union_classes:
return super()._validate_oapg(arg, validation_metadata=validation_metadata)
raise cls.__get_type_error(
arg,
validation_metadata.path_to_item,
union_classes,
key_type=False,
)
return SchemaTypeChecker
class EnumMakerBase:
pass
@ -1989,7 +2026,6 @@ class ComposedBase(Discriminable):
# DictBase, ListBase, NumberBase, StrBase, BoolBase, NoneBase
class ComposedSchema(
SchemaTypeCheckerClsFactory(typing.Union[NoneClass, str, decimal.Decimal, BoolClass, tuple, frozendict.frozendict]),
ComposedBase,
DictBase,
ListBase,
@ -2010,7 +2046,6 @@ class ComposedSchema(
class ListSchema(
SchemaTypeCheckerClsFactory(tuple),
ListBase,
Schema,
TupleMixin
@ -2025,7 +2060,6 @@ class ListSchema(
class NoneSchema(
SchemaTypeCheckerClsFactory(NoneClass),
NoneBase,
Schema,
NoneMixin
@ -2040,7 +2074,6 @@ class NoneSchema(
class NumberSchema(
SchemaTypeCheckerClsFactory(decimal.Decimal),
NumberBase,
Schema,
DecimalMixin
@ -2236,7 +2269,6 @@ class Float64Schema(
class StrSchema(
SchemaTypeCheckerClsFactory(str),
StrBase,
Schema,
StrMixin
@ -2289,8 +2321,8 @@ class DecimalSchema(DecimalBase, StrSchema):
class BytesSchema(
SchemaTypeCheckerClsFactory(bytes),
Schema,
BytesMixin
):
"""
this class will subclass bytes and is immutable
@ -2300,8 +2332,8 @@ class BytesSchema(
class FileSchema(
SchemaTypeCheckerClsFactory(FileIO),
Schema,
FileMixin
):
"""
This class is NOT immutable
@ -2329,7 +2361,6 @@ class BinaryBase:
class BinarySchema(
SchemaTypeCheckerClsFactory(typing.Union[bytes, FileIO]),
ComposedBase,
BinaryBase,
Schema,
@ -2346,7 +2377,6 @@ class BinarySchema(
class BoolSchema(
SchemaTypeCheckerClsFactory(BoolClass),
BoolBase,
Schema,
BoolMixin
@ -2361,9 +2391,6 @@ class BoolSchema(
class AnyTypeSchema(
SchemaTypeCheckerClsFactory(
typing.Union[frozendict.frozendict, tuple, decimal.Decimal, str, BoolClass, NoneClass, bytes, FileIO]
),
DictBase,
ListBase,
NumberBase,
@ -2371,7 +2398,7 @@ class AnyTypeSchema(
BoolBase,
NoneBase,
Schema,
NoneFrozenDictTupleStrDecimalBoolMixin
NoneFrozenDictTupleStrDecimalBoolFileBytesMixin
):
# Python representation of a schema defined as true or {}
pass
@ -2407,7 +2434,6 @@ class NotAnyTypeSchema(
class DictSchema(
SchemaTypeCheckerClsFactory(frozendict.frozendict),
DictBase,
Schema,
FrozenDictMixin

View File

@ -33,6 +33,7 @@ class AdditionalpropertiesAllowsASchemaWhichShouldValidate(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
bar = schemas.AnyTypeSchema

View File

@ -33,6 +33,7 @@ class AdditionalpropertiesAllowsASchemaWhichShouldValidate(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
bar = schemas.AnyTypeSchema

View File

@ -33,6 +33,7 @@ class AdditionalpropertiesAreAllowedByDefault(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
bar = schemas.AnyTypeSchema

View File

@ -33,6 +33,7 @@ class AdditionalpropertiesAreAllowedByDefault(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
bar = schemas.AnyTypeSchema

View File

@ -42,6 +42,7 @@ class AdditionalpropertiesShouldNotLookInApplicators(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
__annotations__ = {

View File

@ -42,6 +42,7 @@ class AdditionalpropertiesShouldNotLookInApplicators(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
__annotations__ = {

View File

@ -44,6 +44,7 @@ class Allof(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -99,6 +100,7 @@ class Allof(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -44,6 +44,7 @@ class Allof(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -99,6 +100,7 @@ class Allof(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class AllofWithBaseSchema(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -52,6 +53,7 @@ class AllofWithBaseSchema(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {
@ -107,6 +109,7 @@ class AllofWithBaseSchema(
required = {
"baz",
}
class properties:
baz = schemas.NoneSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class AllofWithBaseSchema(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -52,6 +53,7 @@ class AllofWithBaseSchema(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {
@ -107,6 +109,7 @@ class AllofWithBaseSchema(
required = {
"baz",
}
class properties:
baz = schemas.NoneSchema
__annotations__ = {

View File

@ -44,6 +44,7 @@ class AnyofComplexTypes(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -99,6 +100,7 @@ class AnyofComplexTypes(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -44,6 +44,7 @@ class AnyofComplexTypes(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -99,6 +100,7 @@ class AnyofComplexTypes(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class EnumsInProperties(
required = {
"bar",
}
class properties:

View File

@ -36,6 +36,7 @@ class EnumsInProperties(
required = {
"bar",
}
class properties:

View File

@ -33,6 +33,7 @@ class ForbiddenProperty(
class MetaOapg:
class properties:
foo = schemas.NotAnyTypeSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class ForbiddenProperty(
class MetaOapg:
class properties:
foo = schemas.NotAnyTypeSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class InvalidStringValueForDefault(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class InvalidStringValueForDefault(
class MetaOapg:
class properties:

View File

@ -41,6 +41,7 @@ class NotMoreComplexSchema(
class MetaOapg:
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -41,6 +41,7 @@ class NotMoreComplexSchema(
class MetaOapg:
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class ObjectPropertiesValidation(
class MetaOapg:
class properties:
foo = schemas.IntSchema
bar = schemas.StrSchema

View File

@ -33,6 +33,7 @@ class ObjectPropertiesValidation(
class MetaOapg:
class properties:
foo = schemas.IntSchema
bar = schemas.StrSchema

View File

@ -44,6 +44,7 @@ class OneofComplexTypes(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -99,6 +100,7 @@ class OneofComplexTypes(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -44,6 +44,7 @@ class OneofComplexTypes(
required = {
"bar",
}
class properties:
bar = schemas.IntSchema
__annotations__ = {
@ -99,6 +100,7 @@ class OneofComplexTypes(
required = {
"foo",
}
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class PropertiesWithEscapedCharacters(
class MetaOapg:
class properties:
foo_nbar = schemas.NumberSchema
foo_bar = schemas.NumberSchema

View File

@ -33,6 +33,7 @@ class PropertiesWithEscapedCharacters(
class MetaOapg:
class properties:
foo_nbar = schemas.NumberSchema
foo_bar = schemas.NumberSchema

View File

@ -33,6 +33,7 @@ class PropertyNamedRefThatIsNotAReference(
class MetaOapg:
class properties:
ref = schemas.StrSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class PropertyNamedRefThatIsNotAReference(
class MetaOapg:
class properties:
ref = schemas.StrSchema
__annotations__ = {

View File

@ -33,7 +33,7 @@ class RefInItems(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['PropertyNamedRefThatIsNotAReference']:

View File

@ -33,7 +33,7 @@ class RefInItems(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['PropertyNamedRefThatIsNotAReference']:

View File

@ -33,6 +33,7 @@ class RefInProperty(
class MetaOapg:
class properties:
@classmethod

View File

@ -33,6 +33,7 @@ class RefInProperty(
class MetaOapg:
class properties:
@classmethod

View File

@ -33,6 +33,7 @@ class RequiredDefaultValidation(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class RequiredDefaultValidation(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class RequiredValidation(
required = {
"foo",
}
class properties:
foo = schemas.AnyTypeSchema
bar = schemas.AnyTypeSchema

View File

@ -36,6 +36,7 @@ class RequiredValidation(
required = {
"foo",
}
class properties:
foo = schemas.AnyTypeSchema
bar = schemas.AnyTypeSchema

View File

@ -33,6 +33,7 @@ class RequiredWithEmptyArray(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class RequiredWithEmptyArray(
class MetaOapg:
class properties:
foo = schemas.AnyTypeSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing(
class MetaOapg:
class properties:

View File

@ -42,6 +42,7 @@ class SchemaForRequestBodyApplicationJson(
class MetaOapg:
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -40,6 +40,7 @@ class SchemaForRequestBodyApplicationJson(
class MetaOapg:
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -41,6 +41,7 @@ class SchemaFor200ResponseBodyApplicationJson(
class MetaOapg:
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -39,6 +39,7 @@ class SchemaFor200ResponseBodyApplicationJson(
class MetaOapg:
class properties:
foo = schemas.StrSchema
__annotations__ = {

View File

@ -243,8 +243,60 @@ class Schema:
the base class of all swagger/openapi schemas/models
"""
__inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict.frozendict, FileIO, bytes, BoolClass, NoneClass}
_types: typing.Set[typing.Type]
MetaOapg = MetaOapgTyped
@staticmethod
def __get_valid_classes_phrase(input_classes):
"""Returns a string phrase describing what types are allowed"""
all_classes = list(input_classes)
all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
all_class_names = [cls.__name__ for cls in all_classes]
if len(all_class_names) == 1:
return "is {0}".format(all_class_names[0])
return "is one of [{0}]".format(", ".join(all_class_names))
@classmethod
def __type_error_message(
cls, var_value=None, var_name=None, valid_classes=None, key_type=None
):
"""
Keyword Args:
var_value (any): the variable which has the type_error
var_name (str): the name of the variable which has the typ error
valid_classes (tuple): the accepted classes for current_item's
value
key_type (bool): False if our value is a value in a dict
True if it is a key in a dict
False if our item is an item in a tuple
"""
key_or_value = "value"
if key_type:
key_or_value = "key"
valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes)
msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format(
var_name,
key_or_value,
valid_classes_phrase,
type(var_value).__name__,
)
return msg
@classmethod
def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False):
error_msg = cls.__type_error_message(
var_name=path_to_item[-1],
var_value=var_value,
valid_classes=valid_classes,
key_type=key_type,
)
return ApiTypeError(
error_msg,
path_to_item=path_to_item,
valid_classes=valid_classes,
key_type=key_type,
)
@classmethod
def _validate_oapg(
cls,
@ -253,21 +305,8 @@ class Schema:
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict.frozendict, tuple]]]:
"""
Schema _validate_oapg
Runs all schema validation logic and
returns a dynamic class of different bases depending upon the input
This makes it so:
- the returned instance is always a subclass of our defining schema
- this allows us to check type based on whether an instance is a subclass of a schema
- the returned instance is a serializable type (except for None, True, and False) which are enums
Use cases:
1. inheritable type: string/decimal.Decimal/frozendict.frozendict/tuple
2. singletons: bool/None -> uses the base classes BoolClass/NoneClass
Required Steps:
1. verify type of input is valid vs the allowed _types
2. check validations that are applicable for this type of input
3. if enums exist, check that the value exists in the enum
All keyword validation except for type checking was done in calling stack frames
If those validations passed, the validated classes are collected in path_to_schemas
Returns:
path_to_schemas: a map of path to schemas
@ -277,6 +316,14 @@ class Schema:
ApiTypeError: when the input type is not in the list of allowed spec types
"""
base_class = type(arg)
if base_class not in cls._types:
raise cls.__get_type_error(
arg,
validation_metadata.path_to_item,
cls._types,
key_type=False,
)
path_to_schemas = {validation_metadata.path_to_item: set()}
path_to_schemas[validation_metadata.path_to_item].add(cls)
path_to_schemas[validation_metadata.path_to_item].add(base_class)
@ -515,6 +562,8 @@ if typing.TYPE_CHECKING:
StrMixin = str
DecimalMixin = decimal.Decimal
BoolMixin = BoolClass
BytesMixin = bytes
FileMixin = FileIO
# qty 2
class BinaryMixin(bytes, FileIO):
pass
@ -636,77 +685,151 @@ if typing.TYPE_CHECKING:
# qty 6
class NoneFrozenDictTupleStrDecimalBoolMixin(NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass):
pass
# qty 8
class NoneFrozenDictTupleStrDecimalBoolFileBytesMixin(NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass, FileIO, bytes):
pass
else:
# qty 1
NoneMixin = object
FrozenDictMixin = object
TupleMixin = object
StrMixin = object
DecimalMixin = object
BoolMixin = object
class NoneMixin:
_types = {NoneClass}
class FrozenDictMixin:
_types = {frozendict.frozendict}
class TupleMixin:
_types = {tuple}
class StrMixin:
_types = {str}
class DecimalMixin:
_types = {decimal.Decimal}
class BoolMixin:
_types = {BoolClass}
class BytesMixin:
_types = {bytes}
class FileMixin:
_types = {FileIO}
# qty 2
BinaryMixin = object
NoneFrozenDictMixin = object
NoneTupleMixin = object
NoneStrMixin = object
NoneDecimalMixin = object
NoneBoolMixin = object
FrozenDictTupleMixin = object
FrozenDictStrMixin = object
FrozenDictDecimalMixin = object
FrozenDictBoolMixin = object
TupleStrMixin = object
TupleDecimalMixin = object
TupleBoolMixin = object
StrDecimalMixin = object
StrBoolMixin = object
DecimalBoolMixin = object
class BinaryMixin:
_types = {bytes, FileIO}
class NoneFrozenDictMixin:
_types = {NoneClass, frozendict.frozendict}
class NoneTupleMixin:
_types = {NoneClass, tuple}
class NoneStrMixin:
_types = {NoneClass, str}
class NoneDecimalMixin:
_types = {NoneClass, decimal.Decimal}
class NoneBoolMixin:
_types = {NoneClass, BoolClass}
class FrozenDictTupleMixin:
_types = {frozendict.frozendict, tuple}
class FrozenDictStrMixin:
_types = {frozendict.frozendict, str}
class FrozenDictDecimalMixin:
_types = {frozendict.frozendict, decimal.Decimal}
class FrozenDictBoolMixin:
_types = {frozendict.frozendict, BoolClass}
class TupleStrMixin:
_types = {tuple, str}
class TupleDecimalMixin:
_types = {tuple, decimal.Decimal}
class TupleBoolMixin:
_types = {tuple, BoolClass}
class StrDecimalMixin:
_types = {str, decimal.Decimal}
class StrBoolMixin:
_types = {str, BoolClass}
class DecimalBoolMixin:
_types = {decimal.Decimal, BoolClass}
# qty 3
NoneFrozenDictTupleMixin = object
NoneFrozenDictStrMixin = object
NoneFrozenDictDecimalMixin = object
NoneFrozenDictBoolMixin = object
NoneTupleStrMixin = object
NoneTupleDecimalMixin = object
NoneTupleBoolMixin = object
NoneStrDecimalMixin = object
NoneStrBoolMixin = object
NoneDecimalBoolMixin = object
FrozenDictTupleStrMixin = object
FrozenDictTupleDecimalMixin = object
FrozenDictTupleBoolMixin = object
FrozenDictStrDecimalMixin = object
FrozenDictStrBoolMixin = object
FrozenDictDecimalBoolMixin = object
TupleStrDecimalMixin = object
TupleStrBoolMixin = object
TupleDecimalBoolMixin = object
StrDecimalBoolMixin = object
class NoneFrozenDictTupleMixin:
_types = {NoneClass, frozendict.frozendict, tuple}
class NoneFrozenDictStrMixin:
_types = {NoneClass, frozendict.frozendict, str}
class NoneFrozenDictDecimalMixin:
_types = {NoneClass, frozendict.frozendict, decimal.Decimal}
class NoneFrozenDictBoolMixin:
_types = {NoneClass, frozendict.frozendict, BoolClass}
class NoneTupleStrMixin:
_types = {NoneClass, tuple, str}
class NoneTupleDecimalMixin:
_types = {NoneClass, tuple, decimal.Decimal}
class NoneTupleBoolMixin:
_types = {NoneClass, tuple, BoolClass}
class NoneStrDecimalMixin:
_types = {NoneClass, str, decimal.Decimal}
class NoneStrBoolMixin:
_types = {NoneClass, str, BoolClass}
class NoneDecimalBoolMixin:
_types = {NoneClass, decimal.Decimal, BoolClass}
class FrozenDictTupleStrMixin:
_types = {frozendict.frozendict, tuple, str}
class FrozenDictTupleDecimalMixin:
_types = {frozendict.frozendict, tuple, decimal.Decimal}
class FrozenDictTupleBoolMixin:
_types = {frozendict.frozendict, tuple, BoolClass}
class FrozenDictStrDecimalMixin:
_types = {frozendict.frozendict, str, decimal.Decimal}
class FrozenDictStrBoolMixin:
_types = {frozendict.frozendict, str, BoolClass}
class FrozenDictDecimalBoolMixin:
_types = {frozendict.frozendict, decimal.Decimal, BoolClass}
class TupleStrDecimalMixin:
_types = {tuple, str, decimal.Decimal}
class TupleStrBoolMixin:
_types = {tuple, str, BoolClass}
class TupleDecimalBoolMixin:
_types = {tuple, decimal.Decimal, BoolClass}
class StrDecimalBoolMixin:
_types = {str, decimal.Decimal, BoolClass}
# qty 4
NoneFrozenDictTupleStrMixin = object
NoneFrozenDictTupleDecimalMixin = object
NoneFrozenDictTupleBoolMixin = object
NoneFrozenDictStrDecimalMixin = object
NoneFrozenDictStrBoolMixin = object
NoneFrozenDictDecimalBoolMixin = object
NoneTupleStrDecimalMixin = object
NoneTupleStrBoolMixin = object
NoneTupleDecimalBoolMixin = object
NoneStrDecimalBoolMixin = object
FrozenDictTupleStrDecimalMixin = object
FrozenDictTupleStrBoolMixin = object
FrozenDictTupleDecimalBoolMixin = object
FrozenDictStrDecimalBoolMixin = object
TupleStrDecimalBoolMixin = object
class NoneFrozenDictTupleStrMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str}
class NoneFrozenDictTupleDecimalMixin:
_types = {NoneClass, frozendict.frozendict, tuple, decimal.Decimal}
class NoneFrozenDictTupleBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, BoolClass}
class NoneFrozenDictStrDecimalMixin:
_types = {NoneClass, frozendict.frozendict, str, decimal.Decimal}
class NoneFrozenDictStrBoolMixin:
_types = {NoneClass, frozendict.frozendict, str, BoolClass}
class NoneFrozenDictDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, decimal.Decimal, BoolClass}
class NoneTupleStrDecimalMixin:
_types = {NoneClass, tuple, str, decimal.Decimal}
class NoneTupleStrBoolMixin:
_types = {NoneClass, tuple, str, BoolClass}
class NoneTupleDecimalBoolMixin:
_types = {NoneClass, tuple, decimal.Decimal, BoolClass}
class NoneStrDecimalBoolMixin:
_types = {NoneClass, str, decimal.Decimal, BoolClass}
class FrozenDictTupleStrDecimalMixin:
_types = {frozendict.frozendict, tuple, str, decimal.Decimal}
class FrozenDictTupleStrBoolMixin:
_types = {frozendict.frozendict, tuple, str, BoolClass}
class FrozenDictTupleDecimalBoolMixin:
_types = {frozendict.frozendict, tuple, decimal.Decimal, BoolClass}
class FrozenDictStrDecimalBoolMixin:
_types = {frozendict.frozendict, str, decimal.Decimal, BoolClass}
class TupleStrDecimalBoolMixin:
_types = {tuple, str, decimal.Decimal, BoolClass}
# qty 5
NoneFrozenDictTupleStrDecimalMixin = object
NoneFrozenDictTupleStrBoolMixin = object
NoneFrozenDictTupleDecimalBoolMixin = object
NoneFrozenDictStrDecimalBoolMixin = object
NoneTupleStrDecimalBoolMixin = object
FrozenDictTupleStrDecimalBoolMixin = object
class NoneFrozenDictTupleStrDecimalMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal}
class NoneFrozenDictTupleStrBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, BoolClass}
class NoneFrozenDictTupleDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, decimal.Decimal, BoolClass}
class NoneFrozenDictStrDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, str, decimal.Decimal, BoolClass}
class NoneTupleStrDecimalBoolMixin:
_types = {NoneClass, tuple, str, decimal.Decimal, BoolClass}
class FrozenDictTupleStrDecimalBoolMixin:
_types = {frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass}
# qty 6
NoneFrozenDictTupleStrDecimalBoolMixin = object
class NoneFrozenDictTupleStrDecimalBoolMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass}
# qty 8
class NoneFrozenDictTupleStrDecimalBoolFileBytesMixin:
_types = {NoneClass, frozendict.frozendict, tuple, str, decimal.Decimal, BoolClass, FileIO, bytes}
class ValidatorBase:
@ -750,92 +873,6 @@ class Validator(typing.Protocol):
pass
def SchemaTypeCheckerClsFactory(union_type_cls: typing.Any) -> Validator:
if typing.get_origin(union_type_cls) is typing.Union:
union_classes = typing.get_args(union_type_cls)
else:
# note: when a union of a single class is passed in, the union disappears
union_classes = tuple([union_type_cls])
"""
I want the type hint... union_type_cls
and to use it as a base class but when I do, I get
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
"""
class SchemaTypeChecker:
@staticmethod
def __get_valid_classes_phrase(input_classes):
"""Returns a string phrase describing what types are allowed"""
all_classes = list(input_classes)
all_classes = sorted(all_classes, key=lambda cls: cls.__name__)
all_class_names = [cls.__name__ for cls in all_classes]
if len(all_class_names) == 1:
return "is {0}".format(all_class_names[0])
return "is one of [{0}]".format(", ".join(all_class_names))
@classmethod
def __type_error_message(
cls, var_value=None, var_name=None, valid_classes=None, key_type=None
):
"""
Keyword Args:
var_value (any): the variable which has the type_error
var_name (str): the name of the variable which has the typ error
valid_classes (tuple): the accepted classes for current_item's
value
key_type (bool): False if our value is a value in a dict
True if it is a key in a dict
False if our item is an item in a tuple
"""
key_or_value = "value"
if key_type:
key_or_value = "key"
valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes)
msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format(
var_name,
key_or_value,
valid_classes_phrase,
type(var_value).__name__,
)
return msg
@classmethod
def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False):
error_msg = cls.__type_error_message(
var_name=path_to_item[-1],
var_value=var_value,
valid_classes=valid_classes,
key_type=key_type,
)
return ApiTypeError(
error_msg,
path_to_item=path_to_item,
valid_classes=valid_classes,
key_type=key_type,
)
@classmethod
def _validate_oapg(
cls,
arg,
validation_metadata: ValidationMetadata,
) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict.frozendict, tuple]]]:
"""
SchemaTypeChecker _validate_oapg
Validates arg's type
"""
arg_type = type(arg)
if arg_type in union_classes:
return super()._validate_oapg(arg, validation_metadata=validation_metadata)
raise cls.__get_type_error(
arg,
validation_metadata.path_to_item,
union_classes,
key_type=False,
)
return SchemaTypeChecker
class EnumMakerBase:
pass
@ -1996,7 +2033,6 @@ class ComposedBase(Discriminable):
# DictBase, ListBase, NumberBase, StrBase, BoolBase, NoneBase
class ComposedSchema(
SchemaTypeCheckerClsFactory(typing.Union[NoneClass, str, decimal.Decimal, BoolClass, tuple, frozendict.frozendict]),
ComposedBase,
DictBase,
ListBase,
@ -2017,7 +2053,6 @@ class ComposedSchema(
class ListSchema(
SchemaTypeCheckerClsFactory(tuple),
ListBase,
Schema,
TupleMixin
@ -2032,7 +2067,6 @@ class ListSchema(
class NoneSchema(
SchemaTypeCheckerClsFactory(NoneClass),
NoneBase,
Schema,
NoneMixin
@ -2047,7 +2081,6 @@ class NoneSchema(
class NumberSchema(
SchemaTypeCheckerClsFactory(decimal.Decimal),
NumberBase,
Schema,
DecimalMixin
@ -2243,7 +2276,6 @@ class Float64Schema(
class StrSchema(
SchemaTypeCheckerClsFactory(str),
StrBase,
Schema,
StrMixin
@ -2296,8 +2328,8 @@ class DecimalSchema(DecimalBase, StrSchema):
class BytesSchema(
SchemaTypeCheckerClsFactory(bytes),
Schema,
BytesMixin
):
"""
this class will subclass bytes and is immutable
@ -2307,8 +2339,8 @@ class BytesSchema(
class FileSchema(
SchemaTypeCheckerClsFactory(FileIO),
Schema,
FileMixin
):
"""
This class is NOT immutable
@ -2336,7 +2368,6 @@ class BinaryBase:
class BinarySchema(
SchemaTypeCheckerClsFactory(typing.Union[bytes, FileIO]),
ComposedBase,
BinaryBase,
Schema,
@ -2353,7 +2384,6 @@ class BinarySchema(
class BoolSchema(
SchemaTypeCheckerClsFactory(BoolClass),
BoolBase,
Schema,
BoolMixin
@ -2368,9 +2398,6 @@ class BoolSchema(
class AnyTypeSchema(
SchemaTypeCheckerClsFactory(
typing.Union[frozendict.frozendict, tuple, decimal.Decimal, str, BoolClass, NoneClass, bytes, FileIO]
),
DictBase,
ListBase,
NumberBase,
@ -2378,7 +2405,7 @@ class AnyTypeSchema(
BoolBase,
NoneBase,
Schema,
NoneFrozenDictTupleStrDecimalBoolMixin
NoneFrozenDictTupleStrDecimalBoolFileBytesMixin
):
# Python representation of a schema defined as true or {}
pass
@ -2414,7 +2441,6 @@ class NotAnyTypeSchema(
class DictSchema(
SchemaTypeCheckerClsFactory(frozendict.frozendict),
DictBase,
Schema,
FrozenDictMixin

View File

@ -33,6 +33,7 @@ class AdditionalPropertiesClass(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class AdditionalPropertiesClass(
class MetaOapg:
class properties:

View File

@ -41,7 +41,7 @@ class AdditionalPropertiesWithArrayOfEnums(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['EnumClass']:

View File

@ -41,7 +41,7 @@ class AdditionalPropertiesWithArrayOfEnums(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['EnumClass']:

View File

@ -46,6 +46,7 @@ class Animal(
'Dog': Dog,
}
}
class properties:
className = schemas.StrSchema
color = schemas.StrSchema

View File

@ -46,6 +46,7 @@ class Animal(
'Dog': Dog,
}
}
class properties:
className = schemas.StrSchema
color = schemas.StrSchema

View File

@ -33,7 +33,7 @@ class AnimalFarm(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['Animal']:

View File

@ -33,7 +33,7 @@ class AnimalFarm(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['Animal']:

View File

@ -33,6 +33,7 @@ class AnyTypeAndFormat(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class AnyTypeAndFormat(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class ApiResponse(
class MetaOapg:
class properties:
code = schemas.Int32Schema
type = schemas.StrSchema

View File

@ -33,6 +33,7 @@ class ApiResponse(
class MetaOapg:
class properties:
code = schemas.Int32Schema
type = schemas.StrSchema

View File

@ -23,7 +23,6 @@ from petstore_api import schemas # noqa: F401
class Apple(
schemas.SchemaTypeCheckerClsFactory(typing.Union[schemas.NoneClass, frozendict.frozendict, ]),
schemas.DictBase,
schemas.NoneBase,
schemas.Schema,
@ -40,6 +39,7 @@ class Apple(
required = {
"cultivar",
}
class properties:

View File

@ -23,7 +23,6 @@ from petstore_api import schemas # noqa: F401
class Apple(
schemas.SchemaTypeCheckerClsFactory(typing.Union[schemas.NoneClass, frozendict.frozendict, ]),
schemas.DictBase,
schemas.NoneBase,
schemas.Schema,
@ -40,6 +39,7 @@ class Apple(
required = {
"cultivar",
}
class properties:

View File

@ -36,6 +36,7 @@ class AppleReq(
required = {
"cultivar",
}
class properties:
cultivar = schemas.StrSchema
mealy = schemas.BoolSchema

View File

@ -36,6 +36,7 @@ class AppleReq(
required = {
"cultivar",
}
class properties:
cultivar = schemas.StrSchema
mealy = schemas.BoolSchema

View File

@ -33,6 +33,7 @@ class ArrayOfArrayOfNumberOnly(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class ArrayOfArrayOfNumberOnly(
class MetaOapg:
class properties:

View File

@ -33,7 +33,7 @@ class ArrayOfEnums(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['StringEnum']:

View File

@ -33,7 +33,7 @@ class ArrayOfEnums(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['StringEnum']:

View File

@ -33,6 +33,7 @@ class ArrayOfNumberOnly(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class ArrayOfNumberOnly(
class MetaOapg:
class properties:

View File

@ -33,6 +33,7 @@ class ArrayTest(
class MetaOapg:
class properties:
@ -118,7 +119,7 @@ class ArrayTest(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['ReadOnlyFirst']:

View File

@ -33,6 +33,7 @@ class ArrayTest(
class MetaOapg:
class properties:
@ -118,7 +119,7 @@ class ArrayTest(
class MetaOapg:
@classmethod
@property
def items(cls) -> typing.Type['ReadOnlyFirst']:

View File

@ -36,6 +36,7 @@ class Banana(
required = {
"lengthCm",
}
class properties:
lengthCm = schemas.NumberSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class Banana(
required = {
"lengthCm",
}
class properties:
lengthCm = schemas.NumberSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class BananaReq(
required = {
"lengthCm",
}
class properties:
lengthCm = schemas.NumberSchema
sweet = schemas.BoolSchema

View File

@ -36,6 +36,7 @@ class BananaReq(
required = {
"lengthCm",
}
class properties:
lengthCm = schemas.NumberSchema
sweet = schemas.BoolSchema

View File

@ -36,6 +36,7 @@ class BasquePig(
required = {
"className",
}
class properties:

View File

@ -36,6 +36,7 @@ class BasquePig(
required = {
"className",
}
class properties:

View File

@ -33,6 +33,7 @@ class Capitalization(
class MetaOapg:
class properties:
smallCamel = schemas.StrSchema
CapitalCamel = schemas.StrSchema

View File

@ -33,6 +33,7 @@ class Capitalization(
class MetaOapg:
class properties:
smallCamel = schemas.StrSchema
CapitalCamel = schemas.StrSchema

View File

@ -41,6 +41,7 @@ class Cat(
class MetaOapg:
class properties:
declawed = schemas.BoolSchema
__annotations__ = {

View File

@ -41,6 +41,7 @@ class Cat(
class MetaOapg:
class properties:
declawed = schemas.BoolSchema
__annotations__ = {

View File

@ -36,6 +36,7 @@ class Category(
required = {
"name",
}
class properties:
name = schemas.StrSchema
id = schemas.Int64Schema

View File

@ -36,6 +36,7 @@ class Category(
required = {
"name",
}
class properties:
name = schemas.StrSchema
id = schemas.Int64Schema

View File

@ -41,6 +41,7 @@ class ChildCat(
class MetaOapg:
class properties:
name = schemas.StrSchema
__annotations__ = {

View File

@ -41,6 +41,7 @@ class ChildCat(
class MetaOapg:
class properties:
name = schemas.StrSchema
__annotations__ = {

View File

@ -35,6 +35,7 @@ class ClassModel(
class MetaOapg:
class properties:
_class = schemas.StrSchema
__annotations__ = {

View File

@ -35,6 +35,7 @@ class ClassModel(
class MetaOapg:
class properties:
_class = schemas.StrSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class Client(
class MetaOapg:
class properties:
client = schemas.StrSchema
__annotations__ = {

View File

@ -33,6 +33,7 @@ class Client(
class MetaOapg:
class properties:
client = schemas.StrSchema
__annotations__ = {

View File

@ -41,6 +41,7 @@ class ComplexQuadrilateral(
class MetaOapg:
class properties:

View File

@ -41,6 +41,7 @@ class ComplexQuadrilateral(
class MetaOapg:
class properties:

View File

@ -43,9 +43,6 @@ class ComposedOneOfDifferentTypes(
schemas.DictSchema
):
class MetaOapg:
def __new__(
cls,
*args: typing.Union[dict, frozendict.frozendict, ],

View File

@ -36,6 +36,7 @@ class DanishPig(
required = {
"className",
}
class properties:

View File

@ -36,6 +36,7 @@ class DanishPig(
required = {
"className",
}
class properties:

View File

@ -41,6 +41,7 @@ class Dog(
class MetaOapg:
class properties:
breed = schemas.StrSchema
__annotations__ = {

View File

@ -41,6 +41,7 @@ class Dog(
class MetaOapg:
class properties:
breed = schemas.StrSchema
__annotations__ = {

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