Repository navigation
feat: JSON Schema support - #5
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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$schemaand 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).$refresolves across files, JSON pointers,$id,$anchorand$dynamicAnchor. A$refthat cannot be resolved becomes a diagnostic; indexing never panics.Mapping to the existing model:
requiredandminItems/maxItemsset their cardinality.$refinallOfis an extension (generalisation).oneOf/anyOfbecome choices, or unions for scalars.enum/const(andoneOfof consts) become enumerations.patternPropertiesandadditionalPropertiesare listed.language: "jsonSchema". Each component carries ajsonblock with its kind, pointer, title, examples and deprecated/read-only flags. Each file carries itsdialect.Diff: works on JSON Schema versions. A property that becomes required, a removed enum value, a new facet, a tighter
maximum/maxItemsor a droppednullableis breaking. Property order is ignored. Reports use JSON terms (object, scalar, property).CLI:
index,serveanddiffaccept.json,.yamland.ymlfiles and folders. A single.jsonside ofdiffis read as a bundle only if it hasformatandcomponents.Viewer:
$refs linked. This replaces the XSD snippet; YAML is shown as JSON..jsonand.yaml.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:
$refinto YAML,$anchor,allOf,oneOf, enums and pattern/additional propertiesOSDM 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.ymland 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
$dynamicRefis resolved statically.if/then/else,not,dependentSchemasanddependentRequiredare not shown.allOfwith more than one$refuses the first one as the base. The properties of the others are copied in.definitions.Generated by Claude Code