jacksmith15 / statham-schema

Statham is a Python Model Parsing Library for JSON Schema.
https://statham-schema.readthedocs.io/en/latest/
MIT License
38 stars 11 forks source link

Access properties from a declared Object #80

Open arthur-proglove opened 3 years ago

arthur-proglove commented 3 years ago

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']
jacksmith15 commented 3 years ago

@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.

arthur-proglove commented 3 years ago

oh thank you! Didn't notice that one