Skip to content

Lint and auto-fix unnecessary allOf wrappers around $ref in modern JSON Schema versions #1737

Closed
@jviotti

Description

@jviotti

Historically, up to Draft 7, the $ref keyword overrides sibling keywords. This resulted in many schema developers being forced to wrap instances of $ref in an applicator like allOf. However, that is no longer necessary in 2019-09 and later.

For example, consider this schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    { "$ref": "https://example.com" }
  ]
}

As long as there is no $ref sibling to allOf, it can be extracted as follows:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "https://example.com" 
}

Of course it applies if there are multiple branches in the allOf, etc.

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