Add JSON Schema validation to JsonInput via AJV#4398
Open
lbwexler wants to merge 1 commit into
Open
Conversation
Introduces optional ajvSchema and ajvOptions props on JsonInput, layering AJV-driven schema validation on top of the existing jsonlint syntax checks. When ajvSchema is provided, validation errors are reported as CodeMirror lint annotations with offsets pointing at the offending property in the source text. Split out of the CodeMirror v6 migration (#4116) to keep that PR focused on the framework upgrade.
Member
Author
|
this is work done originally by Ryan and Pete --- I just split it off from the (orthogonal) CodeMirror upgrade it was bundled with |
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.
Summary
Adds optional schema validation to
JsonInputvia AJV. Split out of #4116 (CodeMirror v6 migration) so each PR has a focused scope.JsonInput:ajvSchema— JSON Schema object passed to AJV for content validationajvOptions— options forwarded to the AJV constructorajvSchemais provided, validation errors are surfaced as CodeMirror lint annotations alongside the existing jsonlint syntax checks. Error highlights point at the offending property in the source text.ajvSchemais omitted, behavior is unchanged from the v6 baseline (jsonlint-only).ajv ~8.17.1.Known limitations / follow-ups
JsonInputrender (new Ajv()+ajv.compile()). Consumers passing a stable schema reference still pay this cost. Worth memoizing.text.indexOf(\"key"`)`, which finds the first occurrence of the property name. If the same key appears in multiple objects, the highlight can land on the wrong one.Both are acceptable for a first cut but worth tracking.
Test plan
npx tsc --noEmitcleanyarn lintcleanajvSchemalints syntax errors as beforeajvSchemaflags schema violations (missing required props, type mismatches,additionalProperties: false)🤖 Generated with Claude Code