json-schema-for-humans
json-schema-for-humans copied to clipboard
Hiding Fields
Is there any way to mark some fields in the schema as private so as to hide them from the generated html?
This is not currently supported.
There is no built-in option for this in JSON schema, but this could be achieved with a special attribute like _hidden
for example.
Or were you thinking of a different way?
A special attribute would be fine for my use-case. Would that be difficult to implement?
I don't think it would be very hard to do. It would have to be disabled by default. Then, the is_displayed
property of SchemaNode
could simply be changed to return False if the configuration calls for hidden fields and the field has a _hidden
attribute in it.
for example, the following schema would not display the age
attribute
{
"$id": "https://example.com/person.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name.",
"title": "Person"
},
"lastName": {
"type": "string",
"description": "The person's last name.",
"title": "Person"
},
"age": {
"description": "Age in years which must be equal to or greater than zero.",
"type": "integer",
"minimum": 0,
"title": "Person",
"_hidden": true
}
}
}
Did you want to submit a PR? I could probably take a look soon-ish otherwise :)
I was able to hack this together without much effort. In my case, I use custom templates and I wanted to hide all properties that started with a '$'. Therefore, I simply modified content.html
and towards the end of the file, it reads:
{# Properties, pattern properties, additional properties #}
{%- for sub_property in schema.iterate_properties -%}
{# Custom modification to remove $ properties from documentation #}
{%- if not sub_property.property_display_name.startswith("$") -%}
{% include "section_properties.html" %}
{%- endif -%}
{%- endfor -%}