diff --git a/config_schema.json b/config_schema.json index 7476452e..701e32e1 100644 --- a/config_schema.json +++ b/config_schema.json @@ -140,6 +140,21 @@ "type": "boolean", "description": "if true generate array restrictions section.\n\n if false, do not generate", "default": true + }, + "properties_table_columns": { + "type": "array", + "description": "array of column names to display in the properties table.\n\n if empty, the default is ['Property','Pattern','Type','Deprecated','Definition','Title/Description']", + "items": { + "type": "string", + "enum": [ + "Property", + "Pattern", + "Type", + "Deprecated", + "Definition", + "Title/Description" + ] + } } } }, diff --git a/json_schema_for_humans/generation_configuration.py b/json_schema_for_humans/generation_configuration.py index 3bb93c32..996c6225 100644 --- a/json_schema_for_humans/generation_configuration.py +++ b/json_schema_for_humans/generation_configuration.py @@ -19,6 +19,15 @@ OFFLINE_JS_FILE_NAMES, ) +DEFAULT_PROPERTIES_TABLE_COLUMNS = [ + "Property", + "Pattern", + "Type", + "Deprecated", + "Definition", + "Title/Description", +] + @dataclass_json @dataclass @@ -62,6 +71,7 @@ def __post_init__(self) -> None: "badge_as_image": False, "show_heading_numbers": True, "show_array_restrictions": True, + "properties_table_columns": DEFAULT_PROPERTIES_TABLE_COLUMNS, } default_template_md_options.update(self.template_md_options or {}) self.template_md_options = default_template_md_options diff --git a/json_schema_for_humans/md_template.py b/json_schema_for_humans/md_template.py index d6b7948a..e5db5dce 100644 --- a/json_schema_for_humans/md_template.py +++ b/json_schema_for_humans/md_template.py @@ -324,42 +324,52 @@ def properties_table(self, schema: SchemaNode) -> List[List]: properties = [] for sub_property in schema.iterate_properties: line: List[str] = [] - # property name - property_name = "+ " if sub_property.is_required_property else "- " - property_name += self.format_link(escape_for_table(sub_property.property_name), sub_property.html_id) - line.append(property_name) - # pattern - line.append("Yes" if sub_property.is_pattern_property else "No") - # type - line.append( - "Combination" if jinja_filters.is_combining(sub_property) else escape_for_table(sub_property.type_name) - ) - # Deprecated - line.append( - self.badge("Deprecated", "red") if jinja_filters.deprecated(self.config, sub_property) else "No" - ) - # Link - if sub_property.should_be_a_link(self.config): - line.append( - "Same as " + self.format_link(sub_property.links_to.link_name, sub_property.links_to.html_id) - ) - elif sub_property.refers_to: - line.append("In " + sub_property.ref_path) - else: - line.append("-") - - # title or description - description = sub_property.description or "-" - if sub_property.title: - description = sub_property.title - - line.append(escape_for_table(description)) + for field in self.config.template_md_options.get("properties_table_columns"): + if field == "Property": + # property name + property_name = "+ " if sub_property.is_required_property else "- " + property_name += self.format_link(escape_for_table(sub_property.property_name), sub_property.html_id) + line.append(property_name) + elif field == "Pattern": + # pattern + line.append("Yes" if sub_property.is_pattern_property else "No") + elif field == "Type": + # type + line.append( + "Combination" if jinja_filters.is_combining(sub_property) else escape_for_table(sub_property.type_name) + ) + elif field == "Deprecated": + # Deprecated + line.append( + self.badge("Deprecated", "red") \ + if jinja_filters.deprecated(self.config, sub_property) \ + else "No" + ) + elif field == "Definition": + # Link + if sub_property.should_be_a_link(self.config): + line.append( + "Same as " + self.format_link(sub_property.links_to.link_name, sub_property.links_to.html_id) + ) + elif sub_property.refers_to: + line.append("In " + sub_property.ref_path) + else: + line.append("-") + elif field == "Title/Description": + # title or description + description = sub_property.description or "-" + if sub_property.title: + description = sub_property.title + line.append(escape_for_table(description)) + else: + raise ValueError(f"Unknown field {field} for properties table") properties.append(line) if properties: # add header - properties.insert(0, ["Property", "Pattern", "Type", "Deprecated", "Definition", "Title/Description"]) + headers = self.config.template_md_options.get("properties_table_columns") + properties.insert(0, headers) return properties diff --git a/tests/generation_configuration_test.py b/tests/generation_configuration_test.py index 5da2a10b..75be68c2 100644 --- a/tests/generation_configuration_test.py +++ b/tests/generation_configuration_test.py @@ -67,6 +67,14 @@ def test_override_template_md_options() -> None: "badge_as_image": False, "show_heading_numbers": True, "show_array_restrictions": True, + "properties_table_columns": [ + "Property", + "Pattern", + "Type", + "Deprecated", + "Definition", + "Title/Definition", + ], } # override badge_as_image key