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

v3 improves enums #188

Merged
merged 2 commits into from
Jul 19, 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 @@ -6,15 +6,15 @@ class {{enumInfo.valueToName.jsonPathPiece.camelCase}}:

@schemas.classproperty
{{#eq @key.type "string"}}
def {{this}}(cls) -> str:
def {{this}}(cls) -> typing_extensions.Literal["{{{@key.value}}}"]:
return {{jsonPathPiece.camelCase}}.validate("{{{@key.value}}}")
{{/eq}}
{{#eq @key.type "number"}}
def {{this}}(cls) -> typing.Union[int, float]:
return {{jsonPathPiece.camelCase}}.validate({{{@key.value}}})
{{/eq}}
{{#eq @key.type "integer"}}
def {{this}}(cls) -> int:
def {{this}}(cls) -> typing_extensions.Literal[{{{@key.value}}}]:
return {{jsonPathPiece.camelCase}}.validate({{{@key.value}}})
{{/eq}}
{{#eq @key.type "boolean"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class EnumWith0DoesNotMatchFalseEnums:

@schemas.classproperty
def POSITIVE_0(cls) -> int:
def POSITIVE_0(cls) -> typing_extensions.Literal[0]:
return EnumWith0DoesNotMatchFalse.validate(0)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class EnumWith1DoesNotMatchTrueEnums:

@schemas.classproperty
def POSITIVE_1(cls) -> int:
def POSITIVE_1(cls) -> typing_extensions.Literal[1]:
return EnumWith1DoesNotMatchTrue.validate(1)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
class EnumWithEscapedCharactersEnums:

@schemas.classproperty
def FOO_LINE_FEED_LF_BAR(cls) -> str:
def FOO_LINE_FEED_LF_BAR(cls) -> typing_extensions.Literal["foo\nbar"]:
return EnumWithEscapedCharacters.validate("foo\nbar")

@schemas.classproperty
def FOO_CARRIAGE_RETURN_CR_BAR(cls) -> str:
def FOO_CARRIAGE_RETURN_CR_BAR(cls) -> typing_extensions.Literal["foo\rbar"]:
return EnumWithEscapedCharacters.validate("foo\rbar")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class FooEnums:

@schemas.classproperty
def FOO(cls) -> str:
def FOO(cls) -> typing_extensions.Literal["foo"]:
return Foo.validate("foo")


Expand Down Expand Up @@ -69,7 +69,7 @@ def validate(
class BarEnums:

@schemas.classproperty
def BAR(cls) -> str:
def BAR(cls) -> typing_extensions.Literal["bar"]:
return Bar.validate("bar")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class NulCharactersInStringsEnums:

@schemas.classproperty
def HELLO_NULL_THERE(cls) -> str:
def HELLO_NULL_THERE(cls) -> typing_extensions.Literal["hello\x00there"]:
return NulCharactersInStrings.validate("hello\x00there")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class SimpleEnumValidationEnums:

@schemas.classproperty
def POSITIVE_1(cls) -> int:
def POSITIVE_1(cls) -> typing_extensions.Literal[1]:
return SimpleEnumValidation.validate(1)

@schemas.classproperty
def POSITIVE_2(cls) -> int:
def POSITIVE_2(cls) -> typing_extensions.Literal[2]:
return SimpleEnumValidation.validate(2)

@schemas.classproperty
def POSITIVE_3(cls) -> int:
def POSITIVE_3(cls) -> typing_extensions.Literal[3]:
return SimpleEnumValidation.validate(3)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class ClassNameEnums:

@schemas.classproperty
def BASQUE_PIG(cls) -> str:
def BASQUE_PIG(cls) -> typing_extensions.Literal["BasquePig"]:
return ClassName.validate("BasquePig")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class QuadrilateralTypeEnums:

@schemas.classproperty
def COMPLEX_QUADRILATERAL(cls) -> str:
def COMPLEX_QUADRILATERAL(cls) -> typing_extensions.Literal["ComplexQuadrilateral"]:
return QuadrilateralType.validate("ComplexQuadrilateral")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
class CurrencyEnums:

@schemas.classproperty
def EUR(cls) -> str:
def EUR(cls) -> typing_extensions.Literal["eur"]:
return Currency.validate("eur")

@schemas.classproperty
def USD(cls) -> str:
def USD(cls) -> typing_extensions.Literal["usd"]:
return Currency.validate("usd")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class ClassNameEnums:

@schemas.classproperty
def DANISH_PIG(cls) -> str:
def DANISH_PIG(cls) -> typing_extensions.Literal["DanishPig"]:
return ClassName.validate("DanishPig")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
class JustSymbolEnums:

@schemas.classproperty
def GREATER_THAN_SIGN_EQUALS_SIGN(cls) -> str:
def GREATER_THAN_SIGN_EQUALS_SIGN(cls) -> typing_extensions.Literal[">="]:
return JustSymbol.validate(">=")

@schemas.classproperty
def DOLLAR_SIGN(cls) -> str:
def DOLLAR_SIGN(cls) -> typing_extensions.Literal["$"]:
return JustSymbol.validate("$")


Expand Down Expand Up @@ -83,11 +83,11 @@ def validate(
class ItemsEnums:

@schemas.classproperty
def FISH(cls) -> str:
def FISH(cls) -> typing_extensions.Literal["fish"]:
return Items.validate("fish")

@schemas.classproperty
def CRAB(cls) -> str:
def CRAB(cls) -> typing_extensions.Literal["crab"]:
return Items.validate("crab")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
class EnumClassEnums:

@schemas.classproperty
def _ABC(cls) -> str:
def _ABC(cls) -> typing_extensions.Literal["_abc"]:
return EnumClass.validate("_abc")

@schemas.classproperty
def HYPHEN_MINUS_EFG(cls) -> str:
def HYPHEN_MINUS_EFG(cls) -> typing_extensions.Literal["-efg"]:
return EnumClass.validate("-efg")

@schemas.classproperty
def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls) -> str:
def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls) -> typing_extensions.Literal["(xyz)"]:
return EnumClass.validate("(xyz)")

@schemas.classproperty
def COUNT_1M(cls) -> str:
def COUNT_1M(cls) -> typing_extensions.Literal["COUNT_1M"]:
return EnumClass.validate("COUNT_1M")

@schemas.classproperty
def COUNT_50M(cls) -> str:
def COUNT_50M(cls) -> typing_extensions.Literal["COUNT_50M"]:
return EnumClass.validate("COUNT_50M")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class EnumStringEnums:

@schemas.classproperty
def UPPER(cls) -> str:
def UPPER(cls) -> typing_extensions.Literal["UPPER"]:
return EnumString.validate("UPPER")

@schemas.classproperty
def LOWER(cls) -> str:
def LOWER(cls) -> typing_extensions.Literal["lower"]:
return EnumString.validate("lower")

@schemas.classproperty
def EMPTY(cls) -> str:
def EMPTY(cls) -> typing_extensions.Literal[""]:
return EnumString.validate("")


Expand Down Expand Up @@ -97,15 +97,15 @@ def validate(
class EnumStringRequiredEnums:

@schemas.classproperty
def UPPER(cls) -> str:
def UPPER(cls) -> typing_extensions.Literal["UPPER"]:
return EnumStringRequired.validate("UPPER")

@schemas.classproperty
def LOWER(cls) -> str:
def LOWER(cls) -> typing_extensions.Literal["lower"]:
return EnumStringRequired.validate("lower")

@schemas.classproperty
def EMPTY(cls) -> str:
def EMPTY(cls) -> typing_extensions.Literal[""]:
return EnumStringRequired.validate("")


Expand Down Expand Up @@ -179,11 +179,11 @@ def validate(
class EnumIntegerEnums:

@schemas.classproperty
def POSITIVE_1(cls) -> int:
def POSITIVE_1(cls) -> typing_extensions.Literal[1]:
return EnumInteger.validate(1)

@schemas.classproperty
def NEGATIVE_1(cls) -> int:
def NEGATIVE_1(cls) -> typing_extensions.Literal[-1]:
return EnumInteger.validate(-1)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TriangleTypeEnums:

@schemas.classproperty
def EQUILATERAL_TRIANGLE(cls) -> str:
def EQUILATERAL_TRIANGLE(cls) -> typing_extensions.Literal["EquilateralTriangle"]:
return TriangleType.validate("EquilateralTriangle")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class IntegerEnumEnums:

@schemas.classproperty
def POSITIVE_0(cls) -> int:
def POSITIVE_0(cls) -> typing_extensions.Literal[0]:
return IntegerEnum.validate(0)

@schemas.classproperty
def POSITIVE_1(cls) -> int:
def POSITIVE_1(cls) -> typing_extensions.Literal[1]:
return IntegerEnum.validate(1)

@schemas.classproperty
def POSITIVE_2(cls) -> int:
def POSITIVE_2(cls) -> typing_extensions.Literal[2]:
return IntegerEnum.validate(2)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class IntegerEnumBigEnums:

@schemas.classproperty
def POSITIVE_10(cls) -> int:
def POSITIVE_10(cls) -> typing_extensions.Literal[10]:
return IntegerEnumBig.validate(10)

@schemas.classproperty
def POSITIVE_11(cls) -> int:
def POSITIVE_11(cls) -> typing_extensions.Literal[11]:
return IntegerEnumBig.validate(11)

@schemas.classproperty
def POSITIVE_12(cls) -> int:
def POSITIVE_12(cls) -> typing_extensions.Literal[12]:
return IntegerEnumBig.validate(12)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class IntegerEnumOneValueEnums:

@schemas.classproperty
def POSITIVE_0(cls) -> int:
def POSITIVE_0(cls) -> typing_extensions.Literal[0]:
return IntegerEnumOneValue.validate(0)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class IntegerEnumWithDefaultValueEnums:

@schemas.classproperty
def POSITIVE_0(cls) -> int:
def POSITIVE_0(cls) -> typing_extensions.Literal[0]:
return IntegerEnumWithDefaultValue.validate(0)

@schemas.classproperty
def POSITIVE_1(cls) -> int:
def POSITIVE_1(cls) -> typing_extensions.Literal[1]:
return IntegerEnumWithDefaultValue.validate(1)

@schemas.classproperty
def POSITIVE_2(cls) -> int:
def POSITIVE_2(cls) -> typing_extensions.Literal[2]:
return IntegerEnumWithDefaultValue.validate(2)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TriangleTypeEnums:

@schemas.classproperty
def ISOSCELES_TRIANGLE(cls) -> str:
def ISOSCELES_TRIANGLE(cls) -> typing_extensions.Literal["IsoscelesTriangle"]:
return TriangleType.validate("IsoscelesTriangle")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
class OpEnums:

@schemas.classproperty
def ADD(cls) -> str:
def ADD(cls) -> typing_extensions.Literal["add"]:
return Op.validate("add")

@schemas.classproperty
def REPLACE(cls) -> str:
def REPLACE(cls) -> typing_extensions.Literal["replace"]:
return Op.validate("replace")

@schemas.classproperty
def TEST(cls) -> str:
def TEST(cls) -> typing_extensions.Literal["test"]:
return Op.validate("test")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
class OpEnums:

@schemas.classproperty
def MOVE(cls) -> str:
def MOVE(cls) -> typing_extensions.Literal["move"]:
return Op.validate("move")

@schemas.classproperty
def COPY(cls) -> str:
def COPY(cls) -> typing_extensions.Literal["copy"]:
return Op.validate("copy")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class OpEnums:

@schemas.classproperty
def REMOVE(cls) -> str:
def REMOVE(cls) -> typing_extensions.Literal["remove"]:
return Op.validate("remove")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def validate(
class AdditionalPropertiesEnums:

@schemas.classproperty
def UPPER(cls) -> str:
def UPPER(cls) -> typing_extensions.Literal["UPPER"]:
return AdditionalProperties3.validate("UPPER")

@schemas.classproperty
def LOWER(cls) -> str:
def LOWER(cls) -> typing_extensions.Literal["lower"]:
return AdditionalProperties3.validate("lower")


Expand Down
Loading