Skip to content

Commit

Permalink
Updating JSON Schema for Humans to latest release. Porting template c…
Browse files Browse the repository at this point in the history
…hanges.

Signed-off-by: Steve Springett <[email protected]>
  • Loading branch information
stevespringett committed Jan 8, 2024
1 parent 033f36d commit 0044906
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 72 deletions.
2 changes: 1 addition & 1 deletion docgen/json/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mkdir -p docs/{1.2,1.3,1.4,1.5,1.6}

# Check to see if generate-schema-doc is executable and is in the path. If not, install JSON Schema for Humans.
if ! [ -x "$(command -v generate-schema-doc)" ]; then
pip3 install json-schema-for-humans==0.44.3
pip3 install json-schema-for-humans==0.47
fi

generate () {
Expand Down
132 changes: 64 additions & 68 deletions docgen/json/templates/cyclonedx/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

{# Display type #}
{%- if not schema is combining -%}
<span class="badge value-type">Type: {{ type_name }}</span>
<span class="badge badge-dark value-type">Type: {{ type_name }}</span>
{%- endif -%}

{%- if schema.format -%}
<span class="badge badge-info value-type">Format: {{ schema.format }}</span>
{%- endif -%}

{# Display default #}
{%- set default_value = schema.default_value -%}
{%- if default_value -%}
{{ " " }}<span class="badge default-value">Default: {{ default_value }}</span>
{{ " " }}<span class="badge badge-success default-value">Default: {{ default_value }}</span>
{%- endif -%}
<br/>

Expand All @@ -37,80 +41,72 @@
{%- elif schema.refers_to -%}
{{ content(schema.refers_to_merged, True) }}
{%- else -%}
{# Handle having oneOf or allOf with only one condition #}
{%- if schema.kw_all_of and (schema.kw_all_of.array_items | length) == 1 -%}
{{ content(schema.kw_all_of.array_items[0]) }}
{%- elif schema.kw_any_of and (schema.kw_any_of.array_items | length) == 1 -%}
{{ content(schema.kw_any_of.array_items[0]) }}
{%- else -%}
{%- if schema.explicit_no_additional_properties -%}
{{ " " }}<span class="badge no-additional">No Additional Properties</span>
{%- endif -%}

{# Combining: allOf, anyOf, oneOf, not #}
{%- if schema.kw_all_of -%}
<div class="all-of-value" id="{{ schema.kw_all_of.html_id }}">{{ tabbed_section("allOf", schema.kw_all_of) }}</div>
{%- endif -%}
{%- if schema.kw_any_of -%}
<div class="any-of-value" id="{{ schema.kw_any_of.html_id }}">{{ tabbed_section("anyOf", schema.kw_any_of) }}</div>
{%- endif -%}
{%- if schema.kw_one_of -%}
<div class="one-of-value" id="{{ schema.kw_one_of.html_id }}">{{ tabbed_section("oneOf", schema.kw_one_of) }}</div>
{%- endif -%}
{%- if schema.kw_not -%}
{% include "section_not.html" %}
{%- endif -%}

{# Enum and const #}
{%- if schema.kw_enum -%}
<div class="enum-value" id="{{ schema.kw_enum.html_id }}">
<h4>Must be one of:</h4>
<ul class="list-group">
{%- for enum_choice in schema.kw_enum.array_items -%}
<li class="list-group-item enum-item">{{ enum_choice.literal | python_to_json }}</li>
{%- endfor -%}
</ul>
</div>
{%- endif -%}
{%- if schema.kw_const -%}
<span class="const-value" id="{{ schema.kw_const.html_id }}">Specific value: <code>{{ schema.kw_const.raw | python_to_json }}</code></span>
{%- endif -%}
{%- if schema.explicit_no_additional_properties -%}
{{ " " }}<span class="badge badge-info no-additional">No Additional Properties</span>
{%- endif -%}

{# Pattern (Regular Expression) #}
{%- if schema.kw_pattern -%}
<span class="pattern-value" id="{{ schema.kw_pattern.html_id }}">Must match regular expression: <code>{{ schema.kw_pattern.literal | escape }}</code></span>
{%- endif -%}
{# Combining: allOf, anyOf, oneOf, not #}
{%- if schema.kw_all_of -%}
<div class="all-of-value" id="{{ schema.kw_all_of.html_id }}">{{ tabbed_section("allOf", schema.kw_all_of) }}</div>
{%- endif -%}
{%- if schema.kw_any_of -%}
<div class="any-of-value" id="{{ schema.kw_any_of.html_id }}">{{ tabbed_section("anyOf", schema.kw_any_of) }}</div>
{%- endif -%}
{%- if schema.kw_one_of -%}
<div class="one-of-value" id="{{ schema.kw_one_of.html_id }}">{{ tabbed_section("oneOf", schema.kw_one_of) }}</div>
{%- endif -%}
{%- if schema.kw_not -%}
{% include "section_not.html" %}
{%- endif -%}

{# Conditional subschema, or if-then-else section #}
{%- if schema.has_conditional -%}
{% include "section_conditional_subschema.html" %}
{%- endif -%}
{# Enum and const #}
{%- if schema.kw_enum -%}
<div class="enum-value" id="{{ schema.kw_enum.html_id }}">
<h4>Must be one of:</h4>
<ul class="list-group">
{%- for enum_choice in schema.kw_enum.array_items -%}
<li class="list-group-item enum-item">{{ enum_choice.literal | python_to_json }}</li>
{%- endfor -%}
</ul>
</div>
{%- endif -%}
{%- if schema.kw_const -%}
<span class="const-value" id="{{ schema.kw_const.html_id }}">Specific value: <code>{{ schema.kw_const.raw | python_to_json }}</code></span>
{%- endif -%}

{# Required properties that are not defined under "properties". They will only be listed #}
{% include "section_undocumented_required_properties.html" %}
{# Pattern (Regular Expression) #}
{%- if schema.kw_pattern -%}
<span class="pattern-value" id="{{ schema.kw_pattern.html_id }}">Must match regular expression: <code>{{ schema.kw_pattern.literal | escape }}</code></span>
{%- endif -%}

{# Show the requested type(s) #}
{% include "badge_type.html" %}
{# Conditional subschema, or if-then-else section #}
{%- if schema.has_conditional -%}
{% include "section_conditional_subschema.html" %}
{%- endif -%}

{# Show array restrictions #}
{%- if type_name.startswith("array") -%}
{% include "section_array.html" %}
{%- endif -%}
{# Required properties that are not defined under "properties". They will only be listed #}
{% include "section_undocumented_required_properties.html" %}

{# Display examples #}
{%- set examples = schema.examples -%}
{%- if examples -%}
{% include "section_examples.html" %}
{%- endif -%}
{# Show the requested type(s) #}
{% include "badge_type.html" %}

{# 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 -%}
{# Show array restrictions #}
{%- if type_name.startswith("array") -%}
{% include "section_array.html" %}
{%- endif -%}

{# Display examples #}
{%- set examples = schema.examples -%}
{%- if examples -%}
{% include "section_examples.html" %}
{%- endif -%}

{# 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 -%}
{%- endif -%}
{%- endmacro -%}
4 changes: 2 additions & 2 deletions docgen/json/templates/cyclonedx/schema_doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function setAnchor(anchorLinkDestination) {

function anchorOnLoad() {
// Added to onload on body, checks if there is an anchor link and if so, expand
let linkTarget = window.location.hash.split("?")[0].split("&")[0];
let linkTarget = decodeURIComponent(window.location.hash.split("?")[0].split("&")[0]);
if (linkTarget[0] === "#") {
linkTarget = linkTarget.substr(1);
}
Expand All @@ -37,7 +37,7 @@ function anchorLink(linkTarget) {
if($( this ).hasClass("collapse")) {
$( this ).collapse("show");
} else if ($( this ).hasClass("tab-pane")) {
// We have the pane and not the the tab itself, find the tab
// We have the pane and not the tab itself, find the tab
const tabToShow = $( "a[href='#" + $( this ).attr("id") + "']" );
if (tabToShow) {
tabToShow.tab("show");
Expand Down
2 changes: 1 addition & 1 deletion docgen/json/templates/cyclonedx/schema_doc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions docgen/json/templates/cyclonedx/section_array.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{%- if schema.kw_unique_items and schema.kw_unique_items.literal == True -%}
{{ restriction("All items must be unique", "unique-items", schema.kw_unique_items.html_id) }}
{%- endif -%}
{%- if not schema.array_additional_items -%}
{{ " " }}<span class="badge badge-info no-additional">No Additional Items</span>
{%- endif -%}
{%- if schema.array_items_def -%}
<h4>Each item of this array must be:</h4>
<div class="card">
Expand Down Expand Up @@ -34,4 +37,12 @@ <h4>At least one of the items must be:</h4>
{{ content(schema.kw_contains) }}
</div>
</div>
{%- endif -%}
{%- if schema.array_additional_items_def -%}
<h4>All other items must be:</h4>
<div class="card">
<div class="card-body items-contain-definition" id="{{ schema.array_additional_items_def.html_id }}">
{{ content(schema.array_additional_items_def) }}
</div>
</div>
{%- endif -%}

0 comments on commit 0044906

Please sign in to comment.