Skip to content

jsonschema lint --fix aborts when a $ref appears inside a patternProperties whose key contains / #670

@Vaibhav701161

Description

@Vaibhav701161

Environment

  • CLI version: jsonschema --version → 14.12.0
  • Node version: (output of node --version)
  • OS: Linux (WSL Ubuntu)

Summary

Running:

jsonschema lint --fix schema.json

fails with:

error: Could not autofix the schema without breaking its internal references
at location "/patternProperties/^~1~1.*/$ref"

The tool aborts safely, but the auto-fix does not complete.

Image

Minimal Reproducible Example

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$defs": {
    "foo": { "description": "ignored" }
  },
  "type": "object",
  "patternProperties": {
    "^//.*": { "$ref": "#/$defs/foo" }
  }
}

Then:

jsonschema lint --fix schema.json

Observed error:

Could not autofix the schema without breaking its internal references
at location "/patternProperties/^~1~1.*/$ref"

Observations

  • The patternProperties key contains /.

  • In JSON Pointer encoding, ^//.* becomes ^~1~1.*.

  • The reported failure location:

    /patternProperties/^~1~1.*/$ref
    

    correctly maps to that key.

The error location suggests the fixer's JSON Pointer decoder/encoder fails to correctly handle the tilde-escaped path when reconstructing updated $ref values during the $defsdefinitions rewrite.

Flattening $defs or removing / from the pattern key avoids the failure.


Question

Is this:

  • A known limitation of pointer reconstruction during auto-fix?
  • An edge case in handling escaped JSON Pointer segments?
  • Expected conservative behavior for certain graph rewrites?

If useful, I can provide additional test cases.

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