Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

v3 adds new overload #184

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,27 @@ public String toString() {
return sb.toString();
}

/**
* A method to get all possible types
* Also returns additional bytes and file as types when type is unset
* @return the allowed types
*/
public LinkedHashSet<String> allTypes() {
if (types != null) {
return types;
}
LinkedHashSet<String> allTypes = new LinkedHashSet<>();
allTypes.add("null");
allTypes.add("boolean");
allTypes.add("number");
allTypes.add("string");
allTypes.add("array");
allTypes.add("object");
allTypes.add("bytes");
allTypes.add("file");
return allTypes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
{{#if types}}
{{#gt types.size 1}}
{{#each types}}
@typing.overload
def __new__(
{{> components/schemas/_helper_new_args }}
) -> {{../jsonPathPiece.camelCase}}{{> components/schemas/_helper_new_generic_type }}
{{/each}}
{{/gt}}
{{else}}
{{#each allTypes}}
@typing.overload
def __new__(
{{> components/schemas/_helper_new_args }}
) -> {{../jsonPathPiece.camelCase}}{{> components/schemas/_helper_new_generic_type }}
{{/each}}
{{/if}}
def __new__(
cls,
{{#if types}}
{{#eq types.size 1}}
{{#contains types "array"}}
arg: typing.Sequence[
{{#with ../items}}
{{#if refInfo.refClass}}
typing.Union[
{{> components/schemas/_helper_new_ref_property_value_type optional=false }}
]
{{else}}
typing.Union[
{{> components/schemas/_helper_new_property_value_type optional=false }}
]
{{/if}}
{{/with}}
],
{{/contains}}
{{#contains types "object"}}
arg: typing.Union[
{{mapInputJsonPathPiece.camelCase}},
{{jsonPathPiece.camelCase}}[frozendict.frozendict],
],
{{/contains}}
{{#contains types "string"}}
arg: {{> _helper_schema_python_types }},
{{/contains}}
{{#contains types "number"}}
arg: typing.Union[{{> _helper_schema_python_types }}],
{{/contains}}
{{#contains types "integer"}}
arg: {{> _helper_schema_python_types }},
{{/contains}}
{{#contains types "boolean"}}
arg: {{> _helper_schema_python_types }},
{{/contains}}
{{#contains types "null"}}
arg: {{> _helper_schema_python_types }},
{{/contains}}
{{#each types}}
{{> components/schemas/_helper_new_args }}
{{/each}}
{{else}}
cls,
arg: typing.Union[
{{#each types}}
{{#eq this "object"}}
Expand All @@ -49,58 +33,24 @@ def __new__(
{{/eq}}
{{/each}}
],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
{{/eq}}
{{else}}
{{#if mapInputJsonPathPiece}}
arg: typing.Union[
{{mapInputJsonPathPiece.camelCase}},
schemas.INPUT_TYPES_ALL_INCL_SCHEMA
],
{{else}}
cls,
arg: schemas.INPUT_TYPES_ALL_INCL_SCHEMA,
{{/if}}
{{/if}}
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
{{/if}}
{{#if types}}
{{#eq types.size 1}}
) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:
{{else}}
) -> {{jsonPathPiece.camelCase}}[
typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]
]:
):
{{/eq}}
{{else}}
) -> {{jsonPathPiece.camelCase}}[
typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]
]:
):
{{/if}}
inst = super().__new__(
return super().__new__(
cls,
arg,
configuration=configuration,
)
inst = typing.cast(
{{#if types}}
{{#eq types.size 1}}
{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}],
{{else}}
{{jsonPathPiece.camelCase}}[
typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]
],
{{/eq}}
{{else}}
{{jsonPathPiece.camelCase}}[
typing.Union[
{{> components/schemas/_helper_schema_python_base_types_newline }}
]
],
{{/if}}
inst
)
return inst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cls,
{{#eq this "array"}}
{{#if ../items}}
arg: typing.Sequence[
{{#with ../items}}
{{#if refInfo.refClass}}
typing.Union[
{{> components/schemas/_helper_new_ref_property_value_type optional=false }}
]
{{else}}
typing.Union[
{{> components/schemas/_helper_new_property_value_type optional=false }}
]
{{/if}}
{{/with}}
],
{{else}}
arg: typing.Sequence[schemas.INPUT_TYPES_ALL_INCL_SCHEMA],
{{/if}}
{{else}}
{{#eq this "object"}}
arg: typing.Union[
{{mapInputJsonPathPiece.camelCase}},
{{jsonPathPiece.camelCase}}[frozendict.frozendict],
],
{{else}}
{{#eq this "string"}}
arg: typing.Union[str, datetime.date, datetime.datetime, uuid.UUID],
{{else}}
{{#eq this "number"}}
arg: typing.Union[decimal.Decimal, float, int],
{{else}}
{{#eq this "integer"}}
arg: typing.Union[decimal.Decimal, int],
{{else}}
{{#eq this "boolean"}}
arg: typing.Union[bool, schemas.BoolClass],
{{else}}
{{#eq this "null"}}
arg: typing.Union[None, schemas.NoneClass],
{{else}}
{{#eq this "bytes"}}
arg: bytes,
{{else}}
{{#eq this "file"}}
arg: io.FileIO,
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{#eq this "array"}}
[tuple]: ...
{{else}}
{{#eq this "object"}}
[frozendict.frozendict]: ...
{{else}}
{{#eq this "string"}}
[str]: ...
{{else}}
{{#eq this "number"}}
[decimal.Decimal]: ...
{{else}}
{{#eq this "integer"}}
[decimal.Decimal]: ...
{{else}}
{{#eq this "boolean"}}
[schemas.BoolClass]: ...
{{else}}
{{#eq this "null"}}
[schemas.NoneClass]: ...
{{else}}
{{#eq this "bytes"}}
[bytes]: ...
{{else}}
{{#eq this "file"}}
[schemas.FileIO]: ...
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,73 @@ class Schema_(metaclass=schemas.SingletonMeta):
not_: typing.Type[Not2] = dataclasses.field(default_factory=lambda: Not2) # type: ignore


@typing.overload
def __new__(
cls,
arg: typing.Union[None, schemas.NoneClass],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[schemas.NoneClass]: ...

@typing.overload
def __new__(
cls,
arg: typing.Union[bool, schemas.BoolClass],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[schemas.BoolClass]: ...

@typing.overload
def __new__(
cls,
arg: typing.Union[decimal.Decimal, float, int],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[decimal.Decimal]: ...

@typing.overload
def __new__(
cls,
arg: typing.Union[str, datetime.date, datetime.datetime, uuid.UUID],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[str]: ...

@typing.overload
def __new__(
cls,
arg: typing.Sequence[schemas.INPUT_TYPES_ALL_INCL_SCHEMA],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[tuple]: ...

@typing.overload
def __new__(
cls,
arg: typing.Union[
DictInput,
schemas.INPUT_TYPES_ALL_INCL_SCHEMA
_Not[frozendict.frozendict],
],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[
typing.Union[
frozendict.frozendict,
str,
decimal.Decimal,
schemas.BoolClass,
schemas.NoneClass,
tuple,
bytes,
schemas.FileIO
]
]:
inst = super().__new__(
) -> _Not[frozendict.frozendict]: ...

@typing.overload
def __new__(
cls,
arg: bytes,
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[bytes]: ...

@typing.overload
def __new__(
cls,
arg: io.FileIO,
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> _Not[schemas.FileIO]: ...

def __new__(
cls,
arg: schemas.INPUT_TYPES_ALL_INCL_SCHEMA,
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
):
return super().__new__(
cls,
arg,
configuration=configuration,
)
inst = typing.cast(
_Not[
typing.Union[
frozendict.frozendict,
str,
decimal.Decimal,
schemas.BoolClass,
schemas.NoneClass,
tuple,
bytes,
schemas.FileIO
]
],
inst
)
return inst

Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,9 @@ def __new__(
],
configuration: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None
) -> AdditionalpropertiesAllowsASchemaWhichShouldValidate[frozendict.frozendict]:
inst = super().__new__(
return super().__new__(
cls,
arg,
configuration=configuration,
)
inst = typing.cast(
AdditionalpropertiesAllowsASchemaWhichShouldValidate[frozendict.frozendict],
inst
)
return inst

Loading