0.3.0-rc1
Pre-releaseEnhancements
-
#64 - Allow property type in user property to be a python enum and translate it to a jsonschema enum
Sometimes a property should have one of a set of strictly enumerated values.
For this use case it is possible to use a PythonEnum
as the property type
of a givenwysdom.UserProperty
:from enum import Enum class Color(Enum): PINK = "pink" ORANGE = "orange" class Vehicle(UserObject): color = UserProperty(Color) >>> my_vehicle = Vehicle({"color": "orange"}) >>> my_vehicle.color <Color.ORANGE: 'orange'>
-
#65 - Regular expression support
If you need to restrict the values that a UserProperty
can take according to a regex pattern, you can specify this
using thepattern
parameter::class Vehicle(UserObject): rgb_hex_color = UserProperty(str, pattern=r"^[0-9a-f]{6}$")
If your dictionary only has certain keys that are valid for your application
according to a regex pattern, you can specify this with the parameter
key_pattern
:color_names = UserProperty( SchemaDict(ColorName), key_pattern=r"^[0-9a-f]{6}$" )
-
#66 - Convenience function: properties
Introduces the convenience function
wysdom.properties
so that:for name, parameter in MyObject.__json_schema_properties__.properties.items():
can be simplified to:
for name, parameter in wysdom.properties(MyObject).items():
-
#67 - Convenience classes: ListProperty and DictProperty
Introduces the convenience classes
wysdom.ListProperty
andwysdom.DictProperty
so that:people_list = UserProperty(SchemaArray(Person))
can be simplified to:
people_list = ListProperty(Person)
and
people_dict = UserProperty(SchemaDict(Person))
can be simplified to:
people_dict = DictProperty(Person)