Skip to content

0.3.0-rc1

Pre-release
Pre-release
Compare
Choose a tag to compare
@jtv8 jtv8 released this 12 Mar 22:57
· 1 commit to master since this release

Enhancements

  • #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 Python Enum as the property type
    of a given wysdom.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 the pattern 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 and wysdom.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)