refactor(docgen): centralize css classes and html ids

Create a single source of truth for all CSS class names and HTML element IDs
used throughout the generated documentation.

New Module (`src/identifiers.rs`):
- `HtmlIds` struct: Static HTML IDs for JS interaction (search, sidebar, etc.)
- `CssClasses` struct: All CSS class names organized by category
- `TypeClasses` struct: Type-specific badge classes (type-string, type-integer, etc.)
- Constants `IDS`, `CSS`, `TYPE_CLASSES` for compile-time access
- Serializable via serde for use in Tera templates

Class Categories:
- Layout: header, layout, main-content
- Sidebar: sidebar, sidebar-open, sidebar-toggle, sidebar-section
- Navigation: nav-list, nav-link, outline-list, outline-item
- Search: search-container, search-results, search-result-item
- Schema: schema-section, properties-container, property, property-header
- Badges: badge, required, deprecated, optional
- Types: type-badge, type-ref, and all type-specific classes
- Nested: nested-schema, array-items, tuple-items, variants
- Definition: definition, definition-name, highlight, usages

Template Updates:
- Replace hardcoded class strings with `{{ css.class_name }}` references
- Replace hardcoded IDs with `{{ ids.id_name }}` references
- Enables IDE navigation and refactoring support

Also adds `schema.json` test fixture (komorebi configuration schema)
This commit is contained in:
LGUG2Z committed 2025-12-22 09:31:29 -08:00
1 parent 8d8780c427
commit 5d606f0d87
7 files changed
+2978 -106

No files matched your search

+2566
View File
File diff suppressed because it is too large. Load diff
+8
View File
@@ -2,6 +2,9 @@
use crate::Error;
use crate::Options;
use crate::identifiers::CSS;
use crate::identifiers::IDS;
use crate::identifiers::TYPE_CLASSES;
use crate::prepare::NavigationData;
use crate::prepare::build_navigation;
use crate::prepare::prepare_for_template;
@@ -108,6 +111,11 @@ impl Generator {
.unwrap_or_default();
context.insert("required_set", &required_set);
// Add CSS classes and HTML IDs from the single source of truth
context.insert("ids", &IDS);
context.insert("css", &CSS);
context.insert("type_classes", &TYPE_CLASSES);
Ok(context)
}
}
+284
View File
@@ -0,0 +1,284 @@
//! Single source of truth for all CSS classes and HTML IDs
//!
//! This module centralizes all identifier strings used in the generated HTML output.
//! By defining them here, we ensure consistency between Rust code, HTML templates,
//! CSS styles, and JavaScript.
use serde::Serialize;
/// Static HTML element IDs used for JavaScript interaction
#[derive(Debug, Clone, Serialize)]
pub struct HtmlIds {
pub search: &'static str,
pub search_results: &'static str,
pub sidebar: &'static str,
pub sidebar_toggle: &'static str,
pub root_schema: &'static str,
pub definitions: &'static str,
}
/// All static HTML IDs
pub const IDS: HtmlIds = HtmlIds {
search: "search",
search_results: "search-results",
sidebar: "sidebar",
sidebar_toggle: "sidebar-toggle",
root_schema: "root-schema",
definitions: "definitions",
};
/// CSS class names organized by category
#[derive(Debug, Clone, Serialize)]
pub struct CssClasses {
// Layout
pub header: &'static str,
pub header_content: &'static str,
pub layout: &'static str,
pub main_content: &'static str,
// Sidebar
pub sidebar: &'static str,
pub sidebar_open: &'static str,
pub sidebar_header: &'static str,
pub sidebar_toggle: &'static str,
pub sidebar_section: &'static str,
pub sidebar_section_title: &'static str,
// Navigation
pub nav_list: &'static str,
pub nav_link: &'static str,
pub outline_list: &'static str,
pub outline_item: &'static str,
pub outline_children: &'static str,
// Search
pub search_container: &'static str,
pub search_results: &'static str,
pub search_results_active: &'static str,
pub search_result_item: &'static str,
pub no_results: &'static str,
pub result_name: &'static str,
pub result_path: &'static str,
pub result_type: &'static str,
// Schema sections
pub schema_section: &'static str,
pub schema_inline: &'static str,
pub properties_container: &'static str,
pub map_entries: &'static str,
// Property
pub property: &'static str,
pub property_header: &'static str,
pub property_name: &'static str,
pub pattern: &'static str,
pub too_deep: &'static str,
// Badges
pub badge: &'static str,
pub required: &'static str,
pub deprecated: &'static str,
pub optional: &'static str,
// Type badges
pub type_badge: &'static str,
pub type_ref: &'static str,
// Map display
pub map_key: &'static str,
pub key_type: &'static str,
pub map_arrow: &'static str,
// Nested schema
pub nested_schema: &'static str,
pub enum_details: &'static str,
pub array_items: &'static str,
pub tuple_items: &'static str,
pub tuple_item: &'static str,
pub tuple_index: &'static str,
// Constraints
pub constraints: &'static str,
pub constraint: &'static str,
pub label: &'static str,
// Variants
pub variants: &'static str,
pub variant: &'static str,
pub enum_values: &'static str,
// Values
pub default_value: &'static str,
pub const_value: &'static str,
// Definition
pub definition: &'static str,
pub definition_name: &'static str,
pub highlight: &'static str,
// Description
pub description: &'static str,
// Usages
pub usages: &'static str,
pub usage_section: &'static str,
pub usage_list: &'static str,
}
/// All CSS class names
pub const CSS: CssClasses = CssClasses {
// Layout
header: "header",
header_content: "header-content",
layout: "layout",
main_content: "main-content",
// Sidebar
sidebar: "sidebar",
sidebar_open: "open",
sidebar_header: "sidebar-header",
sidebar_toggle: "sidebar-toggle",
sidebar_section: "sidebar-section",
sidebar_section_title: "sidebar-section-title",
// Navigation
nav_list: "nav-list",
nav_link: "nav-link",
outline_list: "outline-list",
outline_item: "outline-item",
outline_children: "outline-children",
// Search
search_container: "search-container",
search_results: "search-results",
search_results_active: "active",
search_result_item: "search-result-item",
no_results: "no-results",
result_name: "result-name",
result_path: "result-path",
result_type: "result-type",
// Schema sections
schema_section: "schema-section",
schema_inline: "schema-inline",
properties_container: "properties-container",
map_entries: "map-entries",
// Property
property: "property",
property_header: "property-header",
property_name: "property-name",
pattern: "pattern",
too_deep: "too-deep",
// Badges
badge: "badge",
required: "required",
deprecated: "deprecated",
optional: "optional",
// Type badges
type_badge: "type-badge",
type_ref: "type-ref",
// Map display
map_key: "map-key",
key_type: "key-type",
map_arrow: "map-arrow",
// Nested schema
nested_schema: "nested-schema",
enum_details: "enum-details",
array_items: "array-items",
tuple_items: "tuple-items",
tuple_item: "tuple-item",
tuple_index: "tuple-index",
// Constraints
constraints: "constraints",
constraint: "constraint",
label: "label",
// Variants
variants: "variants",
variant: "variant",
enum_values: "enum-values",
// Values
default_value: "default-value",
const_value: "const-value",
// Definition
definition: "definition",
definition_name: "definition-name",
highlight: "highlight",
// Description
description: "description",
// Usages
usages: "usages",
usage_section: "usage-section",
usage_list: "usage-list",
};
/// Type-specific badge class suffixes (used with type-badge prefix)
#[derive(Debug, Clone, Serialize)]
pub struct TypeClasses {
pub string: &'static str,
pub number: &'static str,
pub integer: &'static str,
pub float: &'static str,
pub boolean: &'static str,
pub null: &'static str,
pub object: &'static str,
pub array: &'static str,
pub r#enum: &'static str,
pub union: &'static str,
pub r#const: &'static str,
}
/// Type-specific badge classes
pub const TYPE_CLASSES: TypeClasses = TypeClasses {
string: "type-string",
number: "type-number",
integer: "type-integer",
float: "type-float",
boolean: "type-boolean",
null: "type-null",
object: "type-object",
array: "type-array",
r#enum: "type-enum",
union: "type-union",
r#const: "type-const",
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_ids_are_valid_html_ids() {
// HTML IDs should not contain spaces and should be lowercase
assert!(!IDS.search.contains(' '));
assert!(!IDS.search_results.contains(' '));
assert!(!IDS.sidebar.contains(' '));
assert!(!IDS.sidebar_toggle.contains(' '));
}
#[test]
fn test_css_classes_are_valid() {
// CSS classes should not contain spaces (multiple classes are separate fields)
assert!(!CSS.header.contains(' '));
assert!(!CSS.property.contains(' '));
assert!(!CSS.type_badge.contains(' '));
}
#[test]
fn test_type_classes_have_prefix() {
// All type classes should start with "type-"
assert!(TYPE_CLASSES.string.starts_with("type-"));
assert!(TYPE_CLASSES.integer.starts_with("type-"));
assert!(TYPE_CLASSES.array.starts_with("type-"));
}
}
+4
View File
@@ -29,9 +29,13 @@
//! ```
mod generator;
pub mod identifiers;
mod prepare;
pub use generator::Generator;
pub use identifiers::CSS;
pub use identifiers::IDS;
pub use identifiers::TYPE_CLASSES;
use schemars::Schema;
use serde_json::Value;
+39 -30
View File
@@ -10,53 +10,56 @@
</style>
</head>
<body>
<header class="header">
<div class="header-content">
<header class="{{ css.header }}">
<div class="{{ css.header_content }}">
<h1>
{{ title_html | default(value="Schema Documentation") | safe
}}
</h1>
<div class="search-container">
<div class="{{ css.search_container }}">
<input
type="search"
id="search"
id="{{ ids.search }}"
placeholder="Search properties and types..."
autocomplete="off"
/>
<div id="search-results" class="search-results"></div>
<div
id="{{ ids.search_results }}"
class="{{ css.search_results }}"
></div>
</div>
</div>
</header>
<div class="layout">
<nav class="sidebar" id="sidebar">
<div class="sidebar-header">
<div class="{{ css.layout }}">
<nav class="{{ css.sidebar }}" id="{{ ids.sidebar }}">
<div class="{{ css.sidebar_header }}">
<h2>Navigation</h2>
<button
class="sidebar-toggle"
id="sidebar-toggle"
class="{{ css.sidebar_toggle }}"
id="{{ ids.sidebar_toggle }}"
aria-label="Toggle sidebar"
>
<span></span>
</button>
</div>
{%- if navigation.outline | length > 0 -%}
<div class="sidebar-section">
<h3 class="sidebar-section-title">Outline</h3>
<ul class="nav-list outline-list">
<div class="{{ css.sidebar_section }}">
<h3 class="{{ css.sidebar_section_title }}">Outline</h3>
<ul class="{{ css.nav_list }} {{ css.outline_list }}">
{%- for entry in navigation.outline -%} {{
macros::render_outline_item(entry=entry, depth=0) }} {%-
endfor -%}
</ul>
</div>
{%- endif -%} {%- if navigation.definitions | length > 0 -%}
<div class="sidebar-section">
<h3 class="sidebar-section-title">Types</h3>
<ul class="nav-list">
<div class="{{ css.sidebar_section }}">
<h3 class="{{ css.sidebar_section_title }}">Types</h3>
<ul class="{{ css.nav_list }}">
{%- for def in navigation.definitions -%}
<li>
<a
href="#{{ def.anchor }}"
class="nav-link"
class="{{ css.nav_link }}"
data-search-name="{{ def.name | lower }}"
>{{ def.display_name | default(value=def.name)
}}</a
@@ -67,11 +70,14 @@
</div>
{%- endif -%}
</nav>
<main class="main-content">
<section id="root-schema" class="schema-section">
<main class="{{ css.main_content }}">
<section
id="{{ ids.root_schema }}"
class="{{ css.schema_section }}"
>
<h2>Configuration</h2>
{%- if schema.properties -%}
<div class="properties-container">
<div class="{{ css.properties_container }}">
{%- for prop_name, prop in schema.properties -%} {%- set
is_required = prop_name in required_set -%} {{
macros::render_property(name=prop_name, node=prop,
@@ -81,19 +87,22 @@
{%- endif -%}
</section>
{%- if schema["$defs"] -%}
<section id="definitions" class="schema-section">
<section
id="{{ ids.definitions }}"
class="{{ css.schema_section }}"
>
<h2>Type Definitions</h2>
{%- for def_name, def in schema["$defs"] -%}
<article
id="{{ def_name | lower }}"
class="definition"
class="{{ css.definition }}"
data-search-name="{{ def_name | lower }}"
>
<h3 class="definition-name">
<h3 class="{{ css.definition_name }}">
{{ def._display_name | default(value=def_name) }}
</h3>
{%- if def.description_html %}
<div class="description">
<div class="{{ css.description }}">
{{ def.description_html | safe }}
</div>
{% endif -%} {{ macros::render_schema(node=def, depth=0,
@@ -101,11 +110,11 @@
type_usages = usages[def_name] -%} {%- if type_usages
and (type_usages.config_usages | length > 0 or
type_usages.type_references | length > 0) -%}
<div class="usages">
<div class="{{ css.usages }}">
{%- if type_usages.config_usages | length > 0 -%}
<div class="usage-section">
<div class="{{ css.usage_section }}">
<h4>Configuration Usage</h4>
<ul class="usage-list">
<ul class="{{ css.usage_list }}">
{%- for usage in type_usages.config_usages
-%}
<li>
@@ -118,9 +127,9 @@
</div>
{%- endif -%} {%- if type_usages.type_references |
length > 0 -%}
<div class="usage-section">
<div class="{{ css.usage_section }}">
<h4>Referenced by</h4>
<ul class="usage-list">
<ul class="{{ css.usage_list }}">
{%- for ref in type_usages.type_references
-%} {%- set ref_display =
display_names[ref.type_name] |
@@ -143,7 +152,7 @@
</main>
</div>
<script>
(function(){const searchInput=document.getElementById('search');const searchResults=document.getElementById('search-results');const searchIndex={{ search_index | json_encode() | safe }};searchInput.addEventListener('input',function(e){const query=e.target.value.toLowerCase().trim();if(!query){searchResults.innerHTML='';searchResults.classList.remove('active');return;}const matches=searchIndex.filter(item=>item.name.toLowerCase().includes(query)||item.path.toLowerCase().includes(query)).slice(0,10);if(matches.length===0){searchResults.innerHTML='<div class="search-result-item no-results">No results found</div>';}else{searchResults.innerHTML=matches.map(item=>`<a href="#${item.anchor}" class="search-result-item"><span class="result-name">${item.name}</span><span class="result-path">${item.path}</span><span class="result-type">${item.entry_type}</span></a>`).join('');}searchResults.classList.add('active');});document.addEventListener('click',function(e){if(!searchInput.contains(e.target)&&!searchResults.contains(e.target)){searchResults.classList.remove('active');}});searchInput.addEventListener('keydown',function(e){if(e.key==='Escape'){searchResults.classList.remove('active');searchInput.blur();}});const sidebarToggle=document.getElementById('sidebar-toggle');const sidebar=document.getElementById('sidebar');if(sidebarToggle&&sidebar){sidebarToggle.addEventListener('click',function(){sidebar.classList.toggle('open');});}document.querySelectorAll('a[href^="#"]').forEach(anchor=>{anchor.addEventListener('click',function(e){const targetId=this.getAttribute('href').slice(1);const target=document.getElementById(targetId);if(target){target.classList.add('highlight');setTimeout(()=>target.classList.remove('highlight'),2000);}if(sidebar){sidebar.classList.remove('open');}searchResults.classList.remove('active');});});})();
(function(){const searchInput=document.getElementById('{{ ids.search }}');const searchResults=document.getElementById('{{ ids.search_results }}');const searchIndex={{ search_index | json_encode() | safe }};searchInput.addEventListener('input',function(e){const query=e.target.value.toLowerCase().trim();if(!query){searchResults.innerHTML='';searchResults.classList.remove('{{ css.search_results_active }}');return;}const matches=searchIndex.filter(item=>item.name.toLowerCase().includes(query)||item.path.toLowerCase().includes(query)).slice(0,10);if(matches.length===0){searchResults.innerHTML='<div class="{{ css.search_result_item }} {{ css.no_results }}">No results found</div>';}else{searchResults.innerHTML=matches.map(item=>`<a href="#${item.anchor}" class="{{ css.search_result_item }}"><span class="{{ css.result_name }}">${item.name}</span><span class="{{ css.result_path }}">${item.path}</span><span class="{{ css.result_type }}">${item.entry_type}</span></a>`).join('');}searchResults.classList.add('{{ css.search_results_active }}');});document.addEventListener('click',function(e){if(!searchInput.contains(e.target)&&!searchResults.contains(e.target)){searchResults.classList.remove('{{ css.search_results_active }}');}});searchInput.addEventListener('keydown',function(e){if(e.key==='Escape'){searchResults.classList.remove('{{ css.search_results_active }}');searchInput.blur();}});const sidebarToggle=document.getElementById('{{ ids.sidebar_toggle }}');const sidebar=document.getElementById('{{ ids.sidebar }}');if(sidebarToggle&&sidebar){sidebarToggle.addEventListener('click',function(){sidebar.classList.toggle('{{ css.sidebar_open }}');});}document.querySelectorAll('a[href^="#"]').forEach(anchor=>{anchor.addEventListener('click',function(e){const targetId=this.getAttribute('href').slice(1);const target=document.getElementById(targetId);if(target){target.classList.add('{{ css.highlight }}');setTimeout(()=>target.classList.remove('{{ css.highlight }}'),2000);}if(sidebar){sidebar.classList.remove('{{ css.sidebar_open }}');}searchResults.classList.remove('{{ css.search_results_active }}');});});})();
</script>
</body>
</html>
+76 -76
View File
@@ -1,12 +1,12 @@
{# Render a hierarchical outline item with collapsible children #}
{% macro render_outline_item(entry, depth) %}
{%- if entry.children | length > 0 -%}
<li class="outline-item depth-{{ depth }}">
<li class="{{ css.outline_item }} depth-{{ depth }}">
<details>
<summary>
<a href="#{{ entry.anchor }}" class="nav-link" data-search-name="{{ entry.name | lower }}">{{ entry.name }}</a>
<a href="#{{ entry.anchor }}" class="{{ css.nav_link }}" data-search-name="{{ entry.name | lower }}">{{ entry.name }}</a>
</summary>
<ul class="outline-children">
<ul class="{{ css.outline_children }}">
{%- for child in entry.children -%}
{{ self::render_outline_item(entry=child, depth=depth + 1) }}
{%- endfor -%}
@@ -14,8 +14,8 @@
</details>
</li>
{%- else -%}
<li class="outline-item depth-{{ depth }}">
<a href="#{{ entry.anchor }}" class="nav-link" data-search-name="{{ entry.name | lower }}">{{ entry.name }}</a>
<li class="{{ css.outline_item }} depth-{{ depth }}">
<a href="#{{ entry.anchor }}" class="{{ css.nav_link }}" data-search-name="{{ entry.name | lower }}">{{ entry.name }}</a>
</li>
{%- endif -%}
{% endmacro render_outline_item %}
@@ -24,20 +24,20 @@
{# Note: Using 'node' instead of 'schema' to avoid conflict with global context #}
{% macro render_property(name, node, required, depth, path) %}
{%- if depth < 10 -%}
<div class="property depth-{{ depth }}" id="{{ path | lower | replace(from=".", to="-") }}" data-search-name="{{ name | lower }}">
<div class="property-header">
<code class="property-name">{{ name }}</code>
{%- if required %}<span class="badge required">required</span>{% endif -%}
{%- if node.deprecated %}<span class="badge deprecated">deprecated</span>{% endif -%}
<div class="{{ css.property }} depth-{{ depth }}" id="{{ path | lower | replace(from=".", to="-") }}" data-search-name="{{ name | lower }}">
<div class="{{ css.property_header }}">
<code class="{{ css.property_name }}">{{ name }}</code>
{%- if required %}<span class="{{ css.badge }} {{ css.required }}">required</span>{% endif -%}
{%- if node.deprecated %}<span class="{{ css.badge }} {{ css.deprecated }}">deprecated</span>{% endif -%}
{{ self::render_type_badge(node=node) }}
</div>
{%- if node.description_html %}<div class="description">{{ node.description_html | safe }}</div>{% endif -%}
{%- if node.description_html %}<div class="{{ css.description }}">{{ node.description_html | safe }}</div>{% endif -%}
{{ self::render_constraints(node=node) }}
{%- if node.default %}<div class="default-value"><span class="label">Default:</span> <code>{{ node.default | json_encode() }}</code></div>{% endif -%}
{%- if node.default %}<div class="{{ css.default_value }}"><span class="{{ css.label }}">Default:</span> <code>{{ node.default | json_encode() }}</code></div>{% endif -%}
{{ self::render_schema_body(node=node, depth=depth, path=path) }}
</div>
{%- else -%}
<div class="property depth-{{ depth }}"><span class="too-deep">Schema nested too deeply. See type definition.</span></div>
<div class="{{ css.property }} depth-{{ depth }}"><span class="{{ css.too_deep }}">Schema nested too deeply. See type definition.</span></div>
{%- endif -%}
{% endmacro render_property %}
@@ -47,7 +47,7 @@
{%- set ref_name = node["$ref"] | replace(from="#/$defs/", to="") -%}
{%- set display = display_names[ref_name] | default(value=ref_name) -%}
{%- set ref_def = schema["$defs"][ref_name] -%}
<a href="#{{ ref_name | lower }}" class="type-ref">{{ display }}</a>
<a href="#{{ ref_name | lower }}" class="{{ css.type_ref }}">{{ display }}</a>
{%- if ref_def._wrapper_inner %} {{ self::render_type_badge(node=ref_def._wrapper_inner) }}{%- endif -%}
{%- elif node.type -%}
{%- if node.type is string -%}
@@ -61,26 +61,26 @@
{%- endif -%}
{%- endfor -%}
{%- if is_homogeneous and first_type.type -%}
<span class="type-badge type-array">array</span> {% if first_type.type == "number" %}<span class="type-badge type-float">float; {{ node.prefixItems | length }}</span>{% else %}<span class="type-badge type-{{ first_type.type }}">{{ first_type.type }}; {{ node.prefixItems | length }}</span>{% endif %}
<span class="{{ css.type_badge }} {{ type_classes.array }}">array</span> {% if first_type.type == "number" %}<span class="{{ css.type_badge }} {{ type_classes.float }}">float; {{ node.prefixItems | length }}</span>{% else %}<span class="{{ css.type_badge }} type-{{ first_type.type }}">{{ first_type.type }}; {{ node.prefixItems | length }}</span>{% endif %}
{%- else -%}
<span class="type-badge type-array">array</span> <span class="type-badge type-array">tuple</span>
<span class="{{ css.type_badge }} {{ type_classes.array }}">array</span> <span class="{{ css.type_badge }} {{ type_classes.array }}">tuple</span>
{%- endif -%}
{%- elif node.type == "array" and node.items -%}
{# Show array with item type as separate badge #}
<span class="type-badge type-array">array</span> {{ self::render_type_badge(node=node.items) }}
<span class="{{ css.type_badge }} {{ type_classes.array }}">array</span> {{ self::render_type_badge(node=node.items) }}
{%- else -%}
<span class="type-badge type-{{ node.type }}">{{ node.type }}</span>
<span class="{{ css.type_badge }} type-{{ node.type }}">{{ node.type }}</span>
{%- endif -%}
{%- else -%}
{# Check for Option<T> pattern: type array with exactly 2 types where one is null #}
{%- if node.type | length == 2 and "null" in node.type -%}
<span class="badge optional">optional</span>
<span class="{{ css.badge }} {{ css.optional }}">optional</span>
{%- for t in node.type -%}
{%- if t != "null" %} {% if t == "array" and node.items %}<span class="type-badge type-array">array</span> {{ self::render_type_badge(node=node.items) }}{% else %}<span class="type-badge type-{{ t }}">{{ t }}</span>{% endif %}
{%- if t != "null" %} {% if t == "array" and node.items %}<span class="{{ css.type_badge }} {{ type_classes.array }}">array</span> {{ self::render_type_badge(node=node.items) }}{% else %}<span class="{{ css.type_badge }} type-{{ t }}">{{ t }}</span>{% endif %}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- for t in node.type %} <span class="type-badge type-{{ t }}">{{ t }}</span>{%- endfor -%}
{%- for t in node.type %} <span class="{{ css.type_badge }} type-{{ t }}">{{ t }}</span>{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- elif node.anyOf -%}
@@ -93,9 +93,9 @@
{%- set first = node.anyOf | first -%}
{%- set second = node.anyOf | last -%}
{%- if second.type and second.type == "null" -%}
<span class="badge optional">optional</span> {{ self::render_type_badge(node=first) }}
<span class="{{ css.badge }} {{ css.optional }}">optional</span> {{ self::render_type_badge(node=first) }}
{%- elif first.type and first.type == "null" -%}
<span class="badge optional">optional</span> {{ self::render_type_badge(node=second) }}
<span class="{{ css.badge }} {{ css.optional }}">optional</span> {{ self::render_type_badge(node=second) }}
{%- else -%}
{# Check if all variants are string const (enum pattern) #}
{%- set_global is_string_enum = true -%}
@@ -107,9 +107,9 @@
{%- endif -%}
{%- endfor -%}
{%- if is_string_enum -%}
<span class="type-badge type-string">string</span> <span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.string }}">string</span> <span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- else -%}
<span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- endif -%}
{%- endif -%}
{%- else -%}
@@ -123,9 +123,9 @@
{%- endif -%}
{%- endfor -%}
{%- if is_string_enum -%}
<span class="type-badge type-string">string</span> <span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.string }}">string</span> <span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- else -%}
<span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- endif -%}
{%- endif -%}
{%- elif node.oneOf -%}
@@ -139,16 +139,16 @@
{%- endif -%}
{%- endfor -%}
{%- if is_string_enum -%}
<span class="type-badge type-string">string</span> <span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.string }}">string</span> <span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- else -%}
<span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- endif -%}
{%- elif node.allOf -%}
<span class="type-badge type-union">allOf</span>
<span class="{{ css.type_badge }} {{ type_classes.union }}">allOf</span>
{%- elif node.const -%}
<span class="type-badge type-const">const</span>
<span class="{{ css.type_badge }} {{ type_classes.const }}">const</span>
{%- elif node.enum -%}
<span class="type-badge type-enum">enum</span>
<span class="{{ css.type_badge }} {{ type_classes.enum }}">enum</span>
{%- endif -%}
{% endmacro render_type_badge %}
@@ -169,15 +169,15 @@
{%- endif -%}
{%- endif -%}
{%- if node.format or node.pattern or node.minimum is defined or node.maximum is defined or node.minLength is defined or node.maxLength is defined or (node.minItems is defined and not skip_item_constraints) or (node.maxItems is defined and not skip_item_constraints) -%}
<div class="constraints">
{%- if node.format %}<span class="constraint"><span class="label">Format:</span> <code>{{ node.format }}</code></span>{% endif -%}
{%- if node.pattern %}<span class="constraint"><span class="label">Pattern:</span> <code>{{ node.pattern }}</code></span>{% endif -%}
{%- if node.minimum is defined %}<span class="constraint"><span class="label">Min:</span> {{ node.minimum }}</span>{% endif -%}
{%- if node.maximum is defined %}<span class="constraint"><span class="label">Max:</span> {{ node.maximum }}</span>{% endif -%}
{%- if node.minLength is defined %}<span class="constraint"><span class="label">Min length:</span> {{ node.minLength }}</span>{% endif -%}
{%- if node.maxLength is defined %}<span class="constraint"><span class="label">Max length:</span> {{ node.maxLength }}</span>{% endif -%}
{%- if node.minItems is defined and not skip_item_constraints %}<span class="constraint"><span class="label">Min items:</span> {{ node.minItems }}</span>{% endif -%}
{%- if node.maxItems is defined and not skip_item_constraints %}<span class="constraint"><span class="label">Max items:</span> {{ node.maxItems }}</span>{% endif -%}
<div class="{{ css.constraints }}">
{%- if node.format %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Format:</span> <code>{{ node.format }}</code></span>{% endif -%}
{%- if node.pattern %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Pattern:</span> <code>{{ node.pattern }}</code></span>{% endif -%}
{%- if node.minimum is defined %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Min:</span> {{ node.minimum }}</span>{% endif -%}
{%- if node.maximum is defined %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Max:</span> {{ node.maximum }}</span>{% endif -%}
{%- if node.minLength is defined %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Min length:</span> {{ node.minLength }}</span>{% endif -%}
{%- if node.maxLength is defined %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Max length:</span> {{ node.maxLength }}</span>{% endif -%}
{%- if node.minItems is defined and not skip_item_constraints %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Min items:</span> {{ node.minItems }}</span>{% endif -%}
{%- if node.maxItems is defined and not skip_item_constraints %}<span class="{{ css.constraint }}"><span class="{{ css.label }}">Max items:</span> {{ node.maxItems }}</span>{% endif -%}
</div>
{%- endif -%}
{% endmacro render_constraints %}
@@ -189,9 +189,9 @@
{# Reference only, already shown as type badge #}
{%- elif node.properties -%}
{%- set required_arr = node.required | default(value=[]) -%}
<details class="nested-schema" open>
<details class="{{ css.nested_schema }}" open>
<summary>Properties ({{ node.properties | length }})</summary>
<div class="properties-container">
<div class="{{ css.properties_container }}">
{%- for prop_name, prop in node.properties -%}
{%- set is_required = prop_name in required_arr -%}
{{ self::render_property(name=prop_name, node=prop, required=is_required, depth=depth + 1, path=path ~ "." ~ prop_name) }}
@@ -199,24 +199,24 @@
</div>
</details>
{%- elif node.patternProperties -%}
<div class="properties-container map-entries">
<div class="{{ css.properties_container }} {{ css.map_entries }}">
{%- for pattern, prop in node.patternProperties -%}
<div class="property depth-{{ depth + 1 }}">
<div class="property-header">
<div class="{{ css.property }} depth-{{ depth + 1 }}">
<div class="{{ css.property_header }}">
{# Convert known patterns to friendly type names - show as quoted string to indicate JSON string key #}
{# Note: patterns use single backslash in the parsed JSON value #}
{%- if pattern == "^\d+$" or pattern == "^[0-9]+$" or pattern == "^-?\d+$" or pattern == "^-?[0-9]+$" -%}
<span class="map-key">"&lt;<span class="key-type">integer</span>&gt;"</span>
<span class="{{ css.map_key }}">"&lt;<span class="{{ css.key_type }}">integer</span>&gt;"</span>
{%- elif pattern == ".*" or pattern == "^.*$" -%}
<span class="map-key">"&lt;<span class="key-type">string</span>&gt;"</span>
<span class="{{ css.map_key }}">"&lt;<span class="{{ css.key_type }}">string</span>&gt;"</span>
{%- else -%}
<code class="property-name pattern">{{ pattern }}</code>
<span class="badge pattern">pattern</span>
<code class="{{ css.property_name }} {{ css.pattern }}">{{ pattern }}</code>
<span class="{{ css.badge }} {{ css.pattern }}">pattern</span>
{%- endif -%}
<span class="map-arrow">→</span>
<span class="{{ css.map_arrow }}">→</span>
{{ self::render_type_badge(node=prop) }}
</div>
{%- if prop.description_html %}<div class="description">{{ prop.description_html | safe }}</div>{% endif -%}
{%- if prop.description_html %}<div class="{{ css.description }}">{{ prop.description_html | safe }}</div>{% endif -%}
{{ self::render_schema_body(node=prop, depth=depth + 1, path=path ~ ".[key]") }}
</div>
{%- endfor -%}
@@ -228,9 +228,9 @@
{# Simple type (string, number, integer, boolean) - already shown in type badge #}
{%- else -%}
{# Complex item type needs dropdown #}
<details class="nested-schema" open>
<details class="{{ css.nested_schema }}" open>
<summary>Array Items</summary>
<div class="array-items">{{ self::render_schema(node=node.items, depth=depth + 1, path=path ~ "[]") }}</div>
<div class="{{ css.array_items }}">{{ self::render_schema(node=node.items, depth=depth + 1, path=path ~ "[]") }}</div>
</details>
{%- endif -%}
{%- elif node.prefixItems -%}
@@ -246,11 +246,11 @@
{# Homogeneous tuple - already shown as [T; N] in badge, no dropdown needed #}
{%- else -%}
{# Heterogeneous tuple - show dropdown #}
<details class="nested-schema" open>
<details class="{{ css.nested_schema }}" open>
<summary>Tuple Items ({{ node.prefixItems | length }})</summary>
<div class="tuple-items">
<div class="{{ css.tuple_items }}">
{%- for item in node.prefixItems -%}
<div class="tuple-item"><span class="tuple-index">[{{ loop.index0 }}]</span>{{ self::render_schema(node=item, depth=depth + 1, path=path ~ "[" ~ loop.index0 ~ "]") }}</div>
<div class="{{ css.tuple_item }}"><span class="{{ css.tuple_index }}">[{{ loop.index0 }}]</span>{{ self::render_schema(node=item, depth=depth + 1, path=path ~ "[" ~ loop.index0 ~ "]") }}</div>
{%- endfor -%}
</div>
</details>
@@ -281,58 +281,58 @@
{%- endif -%}
{%- endfor -%}
{# Render all anyOf variants using full schema rendering #}
<details class="nested-schema enum-details" open>
<details class="{{ css.nested_schema }} {{ css.enum_details }}" open>
<summary>Enum variants ({{ node.anyOf | length }})</summary>
<div class="variants">
<div class="{{ css.variants }}">
{%- for variant in node.anyOf -%}
<div class="variant">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".anyOf[" ~ loop.index0 ~ "]") }}</div>
<div class="{{ css.variant }}">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".anyOf[" ~ loop.index0 ~ "]") }}</div>
{%- endfor -%}
</div>
</details>
{%- endif -%}
{%- else -%}
{# Render all anyOf variants using full schema rendering #}
<details class="nested-schema enum-details" open>
<details class="{{ css.nested_schema }} {{ css.enum_details }}" open>
<summary>Enum variants ({{ node.anyOf | length }})</summary>
<div class="variants">
<div class="{{ css.variants }}">
{%- for variant in node.anyOf -%}
<div class="variant">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".anyOf[" ~ loop.index0 ~ "]") }}</div>
<div class="{{ css.variant }}">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".anyOf[" ~ loop.index0 ~ "]") }}</div>
{%- endfor -%}
</div>
</details>
{%- endif -%}
{%- elif node.oneOf -%}
{# Render all oneOf variants using full schema rendering #}
<details class="nested-schema enum-details" open>
<details class="{{ css.nested_schema }} {{ css.enum_details }}" open>
<summary>Enum variants ({{ node.oneOf | length }})</summary>
<div class="variants">
<div class="{{ css.variants }}">
{%- for variant in node.oneOf -%}
<div class="variant">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".oneOf[" ~ loop.index0 ~ "]") }}</div>
<div class="{{ css.variant }}">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".oneOf[" ~ loop.index0 ~ "]") }}</div>
{%- endfor -%}
</div>
</details>
{%- elif node.allOf -%}
<details class="nested-schema" open>
<details class="{{ css.nested_schema }}" open>
<summary>All of ({{ node.allOf | length }} schemas)</summary>
<div class="variants">
<div class="{{ css.variants }}">
{%- for variant in node.allOf -%}
<div class="variant">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".allOf[" ~ loop.index0 ~ "]") }}</div>
<div class="{{ css.variant }}">{{ self::render_schema(node=variant, depth=depth + 1, path=path ~ ".allOf[" ~ loop.index0 ~ "]") }}</div>
{%- endfor -%}
</div>
</details>
{%- elif node.enum -%}
{%- set enum_count = node.enum | length -%}
<details class="nested-schema enum-details" open>
<details class="{{ css.nested_schema }} {{ css.enum_details }}" open>
<summary>Enum variants ({{ enum_count }})</summary>
<ul class="enum-values">
<ul class="{{ css.enum_values }}">
{%- for value in node.enum -%}<li><code>{{ value | json_encode() }}</code></li>{%- endfor -%}
</ul>
</details>
{%- elif node.const -%}
<div class="const-value"><span class="label">Value:</span> <code>{{ node.const | json_encode() }}</code></div>
<div class="{{ css.const_value }}"><span class="{{ css.label }}">Value:</span> <code>{{ node.const | json_encode() }}</code></div>
{%- endif -%}
{%- if node.additionalProperties and node.additionalProperties is object -%}
<details class="nested-schema" open>
<details class="{{ css.nested_schema }}" open>
<summary>Additional Properties</summary>
{{ self::render_schema(node=node.additionalProperties, depth=depth + 1, path=path ~ ".[*]") }}
</details>
@@ -343,10 +343,10 @@
{# Render a schema without property wrapper #}
{% macro render_schema(node, depth, path) %}
{%- if depth < 10 -%}
<div class="schema-inline">
{{ self::render_type_badge(node=node) }}{%- if node.description_html %} <div class="description">{{ node.description_html | safe }}</div>{% endif -%}
<div class="{{ css.schema_inline }}">
{{ self::render_type_badge(node=node) }}{%- if node.description_html %} <div class="{{ css.description }}">{{ node.description_html | safe }}</div>{% endif -%}
{{ self::render_constraints(node=node) }}
{%- if node.default %}<div class="default-value"><span class="label">Default:</span> <code>{{ node.default | json_encode() }}</code></div>{% endif -%}
{%- if node.default %}<div class="{{ css.default_value }}"><span class="{{ css.label }}">Default:</span> <code>{{ node.default | json_encode() }}</code></div>{% endif -%}
{{ self::render_schema_body(node=node, depth=depth, path=path) }}
</div>
{%- endif -%}
+1
View File
@@ -59,6 +59,7 @@
html {
scroll-behavior: smooth;
font-size: 16px;
scroll-padding-top: 80px;
}
body {