Skip to content

create schema uses anyOf instead of allOf #2008

Open
@george-haroun

Description

@george-haroun

Hello,

Below is an example where interface could be

export type ISchema = ({ foo: string } | { bar: string }) & { baz: string };

Output is

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "anyOf": [
    {
      "additionalProperties": false,
      "properties": {
        "baz": {
          "type": "string"
        },
        "foo": {
          "type": "string"
        }
      },
      "required": [
        "baz",
        "foo"
      ],
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "type": "string"
        },
        "baz": {
          "type": "string"
        }
      },
      "required": [
        "bar",
        "baz"
      ],
      "type": "object"
    }
  ],
  "definitions": {}
}

I am wondering why not using allOf instead since it's more efficient and easier to understand especially when using any schema validation lib so output could be such as

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "allOf": [
    {
      "additionalProperties": false,
      "properties": {
        "baz": {
          "type": "string"
        }
      },
      "required": [
        "baz"
      ],
      "type": "object"
    },
    {
      "anyOf": [
        {
          "additionalProperties": false,
          "properties": {
            "foo": {
              "type": "string"
            }
          },
          "required": [
            "foo"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "bar": {
              "type": "string"
            }
          },
          "required": [
            "bar"
          ],
          "type": "object"
        }
      ]
    }
  ],
  "definitions": {}
}

Do you guys have any clue on how to improve this ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions