Skip to content

validator/propertyNames: fix instanceLocation and keywordLocation - #260

Open
truffle-dev wants to merge 1 commit into
santhosh-tekuri:boonfrom
truffle-dev:fix-propertynames-location
Open

validator/propertyNames: fix instanceLocation and keywordLocation#260
truffle-dev wants to merge 1 commit into
santhosh-tekuri:boonfrom
truffle-dev:fix-propertynames-location

Conversation

@truffle-dev

Copy link
Copy Markdown

Fixes #258.

propertyNames validation called the top-level (*Schema).validate entry to check each property name. That builds a fresh root validator (empty vloc) and wraps the result in a kind.Schema error, so the reported instanceLocation was empty instead of the object's location. The caller then overwrote SchemaURL with PropertyNames.Location, and since kind.PropertyNames.KeywordPath() already returns ["propertyNames"], absoluteKeywordLocation appended a second /propertyNames, producing the duplicated keyword path.

What changed

  • validator.go: added validatePropertyName, a sub-validator that inherits the current vloc and scope (mirroring validateVal/validateValue), so property-name errors carry the object's instance location and the correct relative keyword path. The propertyNames block now wraps the result via addErrors(causes, &kind.PropertyNames{...}), which builds the parent error at the object's location with the inner failures as causes. The meta-resource swap previously inlined here is handled by the sub-validator's handleMeta().
  • validator_test.go: added TestPropertyNamesLocation asserting both the propertyNames error and its cause report instanceLocation /foo and a non-duplicated keywordLocation.

For the issue's example, the output is now:

- at '/foo' [S#/properties/foo/propertyNames]: invalid propertyName 'BAR'
  - at '/foo' [S#/properties/foo/propertyNames/pattern]: 'BAR' does not match pattern '^[a-z]+$'

@santhosh-tekuri
santhosh-tekuri force-pushed the boon branch 3 times, most recently from 7ba9b5e to b0fc661 Compare June 28, 2026 17:38
@truffle-dev
truffle-dev force-pushed the fix-propertynames-location branch from e91b1c8 to 80604bd Compare June 28, 2026 18:19
@truffle-dev

Copy link
Copy Markdown
Author

Rebased onto boon — CLEAN now (80604bd).

4bdda86 fixes the top-level propertyNames instanceLocation, but two things from #258 remain on boon HEAD:

  • keywordLocation still doubles to /properties/foo/propertyNames/propertyNames
  • the nested keyword (pattern) still reports empty instanceLocation

Basic output for #258's example on boon, keywordLocationinstanceLocation:

/properties/foo/propertyNames/pattern        ""
/properties/foo/propertyNames/propertyNames  /foo

The sub-validator here fixes both — TestPropertyNamesLocation fails on boon and passes on this branch.

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.

propertyNames: empty InstanceLocation and duplicated /propertyNames in keywordLocation

1 participant