coveooss / json-schema-for-humans

Quickly generate HTML documentation from a JSON schema
Other
535 stars 102 forks source link

Markdown templates don't support if keyboards with more than 2 layers. #99

Open nicolaszubo opened 3 years ago

nicolaszubo commented 3 years ago

When I try to generate documentation with an if object 2-3 layers deep, it fails with Markdown and mc_nested mode and succeeds on js of flat.

"if": {
                "properties": {
                    "setting": {
                        "properties": {
                            "sampling": {
                                "properties": {
                                    "mode": {
                                        "const": "some_const"
                                    }
                                }                        
                            }
                        }
                    }
                }
            },

Output:

...
  File "/home/username/.local/lib/python3.8/site-packages/json_schema_for_humans/templates/md_nested/section_conditional_subschema.html", line 8, in top-level template code
    {{- first_property.kw_const.literal | python_to_json -}}
  File "/home/username/.local/lib/python3.8/site-packages/json_schema_for_humans/jinja_filters.py", line 83, in python_to_json
    return json.dumps(value, indent=4, separators=(",", ": "), ensure_ascii=False)
  File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Undefined is not JSON serializabl
dblanchette commented 3 years ago

Hi and sorry for the delay.

This is a limitation with the current implementation of the Markdown template. Having too many levels of properties make the result hard to read in Markdown, so it is meant for simpler schemas.

I'm pretty sure we could add a few levels, but I do not have time for big changes in this repository for now, limiting myself to simpler bugfixes.

I cannot say when I will have more time.

As always, feel free to submit a PR anytime and I'll make time to review it!