aromanovich / jsl

A Python DSL for describing JSON schemas
http://jsl.readthedocs.org/
Other
218 stars 21 forks source link

Make Document._fields public ? #15

Closed sebdiem closed 8 years ago

sebdiem commented 8 years ago

Hi I wonder what is the best way to access the fields' names when iterating over a Document fields. With a Document like this:

class Test(jsl.Document):
    test = jsl.StringField()

It is useful to retrieve the dict of fields: {'test': jsl.StringField()} Currently I did not find anything better than Document._fields or Document._backend.properties

Why isn't there public api to access this information?

aromanovich commented 8 years ago

I've changed Document's resolve_and_iter_fields's behaviour: as of the 0.2.0 version, it yields tuples of (name, field). With that change, constructing the fields dict is as simple as dict(Test.resolve_and_iter_fields()).