You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Is your feature request related to a problem? Please describe.
Request for feedback from users of this tool
Describe the solution you'd like
Would people prefer that boolean data stays bool?
Would people prefer that None data stays None?
When do you want classes generated?
a. dict (json object) based classes
b. list (json array) based classes. Note: writing these classes will allow for type hints when accessing values using openapi v3.1.0 prefixItems + acessing a value at a specific index
c. what about composition(oneOf/anyOf/allOf/not) classes?
d. simple data types with validation str/number/int?
Is the fact that all payloads are instances of their validated schema useful to you?
Would people prefer that class instances always identify their base type in the IDE? I added that here with will be included in the next major release:
my_model = MyModel(some_str='a')
# my_model is type MyModel[frozendict.frozendict] in the vscode IDE
# my_model.some_str is type SomeStr[str] in the vscode IDE
Do you not like the deep nesting of classes in the Schema_ class? I fixed that in this PR.
Describe alternatives you've considered
I could restructure the tool to keep boolean values as bool, None values as None and only generate schema classes for
json object models. I could also make it so that payloads are instances of one class only.
json schema validations would still be run
but because the payloads do not subclass all vaidated schemas, validation would be run again if checking if a specific part of a payload is valid to a specific schema. Today validation would NOT need to be rerun because validation results are stored in the generated classes.
Inheriting from a single class would allow enums to be used.
Notes on overloading the __new__ constructor to allow more specific instance types
mypy throws an error if None is returned from __new__
vscode does not understand None returns from __new__ or __call__
so if one wanted None or bool returns, I would need to restructure the generated class and (json) Schema_ information
validated payloads could be instantiated using CompnentNameSchema_.validate(arg)
this can return None/bool without any issue + a ComponentName class that is a TypedDict or subclasses frozendict.
this allows developers access to the Schema_ info, which is stored in the CompnentNameSchema_ class
the IDE would know the return type by adding method overloads of the validate method
this same pattern could be used in other languages too, like Kotlin etc
The proposal would look like this:
class DictNoneOrBoolDict(typing_extensions.TypedDict):
foo: int
bar: str
Class DictNoneOrBoolchema_:
# openapi schema data
types = {bool, dict}
# any needed python data
python_types = typing.Union[bool, None, DictNoneOrBoolDict]
@typing.overload
@classmethod
def valdate(cls, arg: bool) -> bool:
...
@typing.overload
@classmethod
def validate(cls, arg: None) -> None:
...
@typing.overload
@classmethod
def validate(cls, arg: DictOrBoolDict) -> DictNoneOrBoolDict:
...
@classmethod
def validate(cls, arg):
# validation logic invoked here, probably still convert date/datetime/uuiid into str
# Not sure about keeping int/float as Decimal
# If they are kept separate, then int literals could be used for type hints, which would be nice
return arg
Is your feature request related to a problem? Please describe.
Request for feedback from users of this tool
Describe the solution you'd like
a. dict (json object) based classes
b. list (json array) based classes. Note: writing these classes will allow for type hints when accessing values using openapi v3.1.0 prefixItems + acessing a value at a specific index
c. what about composition(oneOf/anyOf/allOf/not) classes?
d. simple data types with validation str/number/int?
Describe alternatives you've considered
I could restructure the tool to keep boolean values as bool, None values as None and only generate schema classes for
json object models. I could also make it so that payloads are instances of one class only.
Inheriting from a single class would allow enums to be used.
Notes on overloading the
__new__constructor to allow more specific instance types__new____new__or__call__CompnentNameSchema_.validate(arg)The proposal would look like this:
Additional context