Skip to content

feat: JSON Schema support - #5

Merged
MathiasVDA merged 8 commits into
mainfrom
json-schema
Oct 21, 2026
Merged

MathiasVDA merged 8 commits into
mainfrom
json-schema

Conversation

@MathiasVDA

Copy link
Copy Markdown
Contributor

Requested by Mathias · project thread

What

JSON Schema support across the core, the CLI, the WebAssembly build and the viewer. OpenAPI and AsyncAPI documents are supported too (the stretch goal).

  • Core (crates/core/src/json.rs): reads JSON Schema draft-04, -06, -07, 2019-09 and 2020-12. The draft comes from $schema and defaults to 2020-12. Files can be JSON or YAML (serde_yaml_ng, works in wasm). It also reads the schemas of OpenAPI 3.0/3.1 (components.schemas) and AsyncAPI 2/3 (schemas and message payloads). $ref resolves across files, JSON pointers, $id, $anchor and $dynamicAnchor. A $ref that cannot be resolved becomes a diagnostic; indexing never panics.

  • Mapping to the existing model:

    • Named schemas become global complex or simple types.
    • Properties become local elements. required and minItems/maxItems set their cardinality.
    • A $ref in allOf is an extension (generalisation).
    • oneOf/anyOf become choices, or unions for scalars.
    • enum/const (and oneOf of consts) become enumerations.
    • Validation keywords become facets.
    • patternProperties and additionalProperties are listed.
    • Bundles carry language: "jsonSchema". Each component carries a json block with its kind, pointer, title, examples and deprecated/read-only flags. Each file carries its dialect.
  • Diff: works on JSON Schema versions. A property that becomes required, a removed enum value, a new facet, a tighter maximum/maxItems or a dropped nullable is breaking. Property order is ignored. Reports use JSON terms (object, scalar, property).

  • CLI: index, serve and diff accept .json, .yaml and .yml files and folders. A single .json side of diff is read as a bundle only if it has format and components.

  • Viewer:

    • Uses JSON terms (objects, scalars, properties, oneOf, inline schemas) and shows the dialect.
    • Shows a JSON view of a component's schema, with $refs linked. This replaces the XSD snippet; YAML is shown as JSON.
    • Shows examples and deprecated/read-only badges.
    • The drop zone and file pickers accept .json and .yaml.
    • Class diagrams, content trees and compare mode work unchanged.
  • Pages examples: the UIC OSDM OpenAPI spec (Apache-2.0) and the JSON Schema 2020-12 meta-schemas (BSD-3-Clause), both fetched at build time.

  • Tests: hand-written fixtures cover:

    • draft 2020-12, with cross-file $ref into YAML, $anchor, allOf, oneOf, enums and pattern/additional properties
    • draft-04
    • OpenAPI 3.0 and AsyncAPI 2.6
    • a v1/v2 diff

    OSDM is a real-world fixture, fetched by scripts/fetch-fixtures.sh (SCHEMA_FIXTURES).

  • CI: GitHub Actions are bumped to their current majors (the Node 20 based ones are deprecated).

  • README, THIRD_PARTY_NOTICES, publiccode and package descriptions are updated.

Results

OSDM 3.11.0 (OSDM-online-api.yml and the 46 files it refers to) indexes to 382 object and 120 scalar definitions with 0 unresolved references, in about 0.1 s (release build).

Known gaps

  • JSON components have no line numbers. The source view finds a schema by its JSON pointer.
  • $dynamicRef is resolved statically.
  • if/then/else, not, dependentSchemas and dependentRequired are not shown.
  • An allOf with more than one $ref uses the first one as the base. The properties of the others are copied in.
  • Swagger 2.0 is handled only through its definitions.

Generated by Claude Code

Reads JSON Schema draft-04, -06, -07, 2019-09 and 2020-12 (picked by
$schema, 2020-12 by default) from in-memory JSON and YAML files, and the
schemas of OpenAPI 3.0/3.1 and AsyncAPI 2/3 documents (components.schemas
and message payloads). $ref is resolved across files, JSON pointers, $id,
$anchor and $dynamicAnchor; unresolved references become diagnostics.

Named schemas become global types, properties local elements with a
cardinality from required and minItems/maxItems, allOf with a $ref an
extension, oneOf/anyOf choices or unions, enum/const enumerations and the
validation keywords facets. Bundles carry language: jsonSchema and a json
block per component (kind, pointer, title, examples, deprecated, ...).
The diff treats JSON facets (minimum, maxItems, nullable, ...) by their
direction and reports use JSON terms.
Hand-written fixtures for draft 2020-12 (cross-file $ref into YAML,
$anchor, allOf inheritance, oneOf, enums, pattern and additional
properties), draft-04, OpenAPI 3.0 and AsyncAPI 2.6, plus a v1/v2 pair for
the diff. OSDM is fetched as a real-world OpenAPI fixture.
…erve and diff

.json, .yaml and .yml files and folders are indexed as JSON Schema when
there is no .xsd file among them; a single .json side of diff is a bundle
only when it has format and components.
Drop zone, file pickers and URLs take .json, .yaml and .yml schemas (a
single .json is a bundle only when it is one). JSON Schema bundles use
JSON terms (objects, scalars, properties, oneOf, inline schemas), show
the dialect, the root schemas of the files, deprecated/read-only badges
and examples, and a JSON view of the component's schema (YAML shown as
JSON) with $ref values linked, instead of the XSD snippet.
checkout v7, cache v6, setup-node v7, upload-artifact v7,
download-artifact v8, upload-pages-artifact v5, deploy-pages v5, the
docker actions and action-gh-release v3: the Node 20 based majors are
deprecated.
…hema examples

Both are fetched at build time like the other examples (OSDM, Apache-2.0,
from its repository; the meta-schemas, BSD-3-Clause, from json-schema.org)
and keep their files under schema/ for the source view.
The intro, features, indexing and diff sections cover JSON Schema; the new
examples are credited in the README and THIRD_PARTY_NOTICES.
@MathiasVDA MathiasVDA self-assigned this Oct 21, 2026
@MathiasVDA
MathiasVDA merged commit a77c3f0 into main Oct 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant