Skip to content

fix: report propertyNames errors on the offending key - #153

Open
tarunagnihotri534 wants to merge 1 commit into
hyperjump-io:mainfrom
tarunagnihotri534:fix/property-names-diagnostic
Open

tarunagnihotri534 wants to merge 1 commit into
hyperjump-io:mainfrom
tarunagnihotri534:fix/property-names-diagnostic

Conversation

@tarunagnihotri534

@tarunagnihotri534 tarunagnihotri534 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #151

What this fixes

When a schema used propertyNames and a document had a key that failed it, the real validation error was never reported on that key. Instead, the server showed "Invalid JSON Pointer" on the document's $schema line.

Root cause

In SchemaValidationDiagnosticsProvider.ts:

  • For propertyNames violations, @hyperjump/json-schema reports instanceLocation as #*<pointer> (for example #*/123 or #*/nested/123).
  • Slicing off the # left */123, which was passed to jsonDocument.findNodeAtPointer. Since it doesn't start with /, @hyperjump/json-pointer threw Invalid JSON Pointer.
  • The outer catch attached that message to /$schema, and the real diagnostic was never created.

Changes

  • Use the existing toPointer helper instead of decodeURIComponent(error.instanceLocation.slice(1)). It already strips the leading *.
  • Report on the key, not the value. When instanceLocation starts with #* and the resolved node belongs to a property, the diagnostic is attached to the property's key node (node.parent.children[0]).
  • The generic catch fallback is unchanged.

Tests

Added to SchemaValidationDiagnosticsProvider.test.ts:

  • a key failing propertyNames gets a diagnostic on that key, and none on $schema
  • multiple failing keys each get their own diagnostic
  • a failing key inside a nested object is placed correctly
  • keys that need JSON Pointer escaping (/ and ~) are placed correctly
  • a document whose keys all pass produces no diagnostics

I confirmed the first test failed before the fix, with "Invalid JSON Pointer" reported on $schema.

Testing

  • vitest run: 20 files, 465 tests pass
  • tsc --noEmit: no errors
  • oxlint src: 0 warnings, 0 errors

Notes

  • This is independent of fix: clear diagnostics when a document is closed #152 and branches from main, so the two shouldn't conflict.
  • I used an AI coding agent (Antigravity with Gemini) to help find this issue and draft the change. I reviewed the diff and ran the tests myself.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong approach. Update JsonDocument.findNodeAtPointer to understand the * syntax. Then it will work everywhere, not just for schema validation diagnostics.

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.

[BUG]: propertyNames validation errors show "Invalid JSON Pointer" on $schema instead of the offending key

2 participants