Skip to content

Error marker highlights colon instead of invalid value #165

@ellanan

Description

@ellanan

Description

When a value fails schema validation (e.g., an invalid type value), the diagnostic from/to positions point to the colon (:) after the property key, rather than the actual invalid value.

Reproduction

Schema:

{
  "type": "object",
  "properties": {
    "type": {
      "anyOf": [
        { "enum": ["object", "array", "string", "number", "integer", "boolean", "null"] },
        { "type": "array", "items": { "enum": ["object", "array", "string", "number", "integer", "boolean", "null"] } }
      ]
    }
  }
}

Document being validated:

{"type": "objectd"}

Expected

The error marker should highlight "objectd" (positions 12–21).

Actual

The diagnostic reports from: 10, to: 11, which is the : character after "type".

{"type": "objectd"}
          ^
          position 10-11 (colon highlighted)

Console output from forEachDiagnostic:

{
  message: 'Value `objectd` at `type` does not match any schema...',
  severity: 'error',
  from: 10,
  to: 11,
  source: 'json-schema'
}

Analysis

In validation.js, the positioning logic uses pointer.valueFrom / pointer.valueTo for non-positional errors (line 137-138). The pointer values appear to be off by one — landing on the separator rather than the value.

Environment

  • codemirror-json-schema: 0.8.1 (latest)
  • @uiw/react-codemirror wrapper

Related: #158 (also about incorrect error marker positions)

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