statham-schema icon indicating copy to clipboard operation
statham-schema copied to clipboard

Access properties from a declared Object

Open arthur-proglove opened this issue 5 years ago • 2 comments

It would be nice to be able to access properties of a model, especially enums.

class MySuperModel(Object):

    my_field: str = Property(String(enum=['foo', 'bar', 'baz]), required=True)


possible_fields = MySuperModel.my_field.element.enum

>>> ['foo', 'bar', 'baz']

arthur-proglove avatar Oct 29 '20 09:10 arthur-proglove

@arthur-proglove this is possible via:

MySuperModel.properties["my_field"].element.enum

I'll leave this open as a reminder to add an some notes about inspection to the docs.

jacksmith15 avatar Oct 29 '20 10:10 jacksmith15

oh thank you! Didn't notice that one

arthur-proglove avatar Oct 29 '20 10:10 arthur-proglove