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

Advanced example for parsing schemas #85

Open andrewmellinger opened 3 years ago

andrewmellinger commented 3 years ago

Greetings! First off, thanks for taking the time to put this together and maintain it. :)

I am trying to build a utility for generating documentation/templates from json schemas as I can't find something out there that works. So I thought I'd try to use the statham parser to generate more outputs. I have been reading through the advanced tutorials on model generation and the API reference but I am having trouble understanding how to iterate (recurse) all the elements. I can't and find the description, default and example properties. Is there any example traverser code or visitor support available?

Thanks!

jacksmith15 commented 3 years ago

Hi @andrewmellinger

default is exposed on each element returned from the get_children iterator, e.g.

from statham.serializers.orderer import get_children

for child_element in get_children(root_element):
    print(element.default)

Unfortunately description and examples are not currently parsed by statham - see https://statham-schema.readthedocs.io/en/latest/compatibility.html#annotations.

Happy to accept a PR which adds support for those annotations!

andrewmellinger commented 3 years ago

Awesome! I haven't dug through your source at all. Can you drop a quick pointer where the default is extracted so I can see how hard/complex it is going to be?

Thanks!