Skip to content

validator/additionalItems: fix instanceLocation#253

Merged
santhosh-tekuri merged 1 commit intosanthosh-tekuri:boonfrom
vnykmshr:fix-additionalitems-index
Feb 18, 2026
Merged

validator/additionalItems: fix instanceLocation#253
santhosh-tekuri merged 1 commit intosanthosh-tekuri:boonfrom
vnykmshr:fix-additionalitems-index

Conversation

@vnykmshr
Copy link
Copy Markdown
Contributor

Fixes #252.

The additionalItems validation loop iterates over arr[evaluated:] which re-indexes from 0, but uses the loop index i directly in strconv.Itoa(i) for the instance location. This reports /0 instead of /2 (or whatever the correct offset is) in validation errors.

What changed

  • validator.go: changed strconv.Itoa(i) to strconv.Itoa(evaluated+i) on line 378
  • additionalitems_test.go: added TestAdditionalItemsErrorLocation using draft-04 schema to verify the error points to the correct array index

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

can you add test case on file based error messages. see invalid_schemas_test.go

this makes it easier to add similar tests easier to just adding to json file without any code change.

Copy link
Copy Markdown
Contributor Author

@vnykmshr vnykmshr Feb 18, 2026

Choose a reason for hiding this comment

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

Moved to a json-driven approach following invalid_schemas_test.go. Created a separate testdata/validation_errors.json + runner since this tests validation errors rather than compile errors. Is
that what you had in mind, or would you prefer the test case added to invalid_schemas.json directly?

@vnykmshr vnykmshr changed the title fix: use absolute index in additionalItems validation loop additionalItems: use absolute index in validation loop Feb 18, 2026
@vnykmshr vnykmshr force-pushed the fix-additionalitems-index branch from b1ff443 to 10b4874 Compare February 18, 2026 17:06
@santhosh-tekuri
Copy link
Copy Markdown
Owner

I added error check support to existing test suite in 8d3372a

  • change commit msg: validator/additionalItems: fix instanceLocation
  • do git pull --rebase from boon branch
  • remove validation_errors.json and validation_errors_test.go
  • add file 'testdata/Extra-Test-Suite/tests/draft2019-09/additionalItems.json` with below content:
[
    {
        "description": "check index in error",
        "schema": {
            "$schema": "https://json-schema.org/draft/2019-09/schema",
            "items": [
                { "type": "string" },
                { "type": "string" }
            ],
            "additionalItems": {
                "type": "boolean"
            }
        },
        "tests": [
            {
                "description": "with fraction",
                "data": [ "a", "b", "c" ],
                "valid": false,
				"errors": [
					"at '/2' [S#/additionalItems/type]: got string, want boolean"
				]
            }
        ]
    }
]

@vnykmshr vnykmshr force-pushed the fix-additionalitems-index branch from 10b4874 to 6dfd9cb Compare February 18, 2026 18:31
@vnykmshr vnykmshr force-pushed the fix-additionalitems-index branch from 6dfd9cb to 6101ad2 Compare February 18, 2026 18:41
@vnykmshr vnykmshr changed the title additionalItems: use absolute index in validation loop validator/additionalItems: fix instanceLocation Feb 18, 2026
@vnykmshr
Copy link
Copy Markdown
Contributor Author

@santhosh-tekuri updated PR as per your review feedback

@santhosh-tekuri santhosh-tekuri merged commit befd2c1 into santhosh-tekuri:boon Feb 18, 2026
3 checks passed
@vnykmshr vnykmshr deleted the fix-additionalitems-index branch February 25, 2026 16:02
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.

additionalItems validation reports wrong instance location

2 participants