Skip to content

Incorrect error instance location for deeply nested data #187

@Hejtmus

Description

@Hejtmus

Hey,

Context

when using Schemasafe for deeply nested data containing invalid data in object contained in array contained in object in an array, the generated error has invalid instanceLocation. This behavior was originally discovered when using Schemasafe within Superforms, see the original issue and with the help of the author, the bug was isolated to Schemasafe.

The problem

This is the data structure in question:

{
  type: 'object',
  additionalProperties: false,
  required: ['arr'],
  properties: {
    arr: {
      type: 'array',
      items: {
        type: 'object',
        additionalProperties: false,
        required: ['arr'],
        properties: {
          arr: {
            type: 'array',
            items: {
              type: 'object',
              additionalProperties: false,
              properties: {
                tryInvalidValue: {
                  type: 'string',
                  minLength: 5
                }
              }
            }
          }
        }
      }
    }
  }
}

Invalid data like this:

{
  arr: [
    {
      arr: [
        {
          tryInvalidValue: '123'
        }
      ]
    }
  ]
}

Should result in this error:

[
  {
    keywordLocation: '#/properties/arr/items/properties/arr/items/properties/tryInvalidValue/minLength',
    instanceLocation: '#/arr/0/arr/0/tryInvalidValue'
  }
]

Instead, Schemasafe generates this error:

[
  {
    keywordLocation: '#/properties/arr/items/properties/arr/items/properties/tryInvalidValue/minLength',
    instanceLocation: '#/arr/0arr/0/tryInvalidValue'
  }
]

In words, the item's index in array is concatenated with the object's key, instead of being separated by delimiter.

More details

For demonstration I made a MRE: https://github.com/Hejtmus/schemasafe-MRE-invalid-error-instance-location

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions