Skip to content

Don't append $ref to the end of the object when dealing with allOf wrappers in unnecessary_allof_ref_wrapper #1826

Closed
@jviotti

Description

@jviotti

Consider this schema:

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

The unnecessary_allof_ref_wrapper linter rule will DELETE allOf and ASSIGN $ref, resulting in $ref getting AFTER allOf, like this:

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

Whereas its cleaner to modify the allOf in place and end up with a schema like this:

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

Another case is this schema:

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

Which will end up as:

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

Whereas ideally it ends up as:

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

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