Skip to content

[Schema Inaccuracy] Bad usage of anyOf to require either or of certain properties in definitions #2510

Open
@wolfy1339

Description

@wolfy1339

Schema Inaccuracy

The schema is trying to use anyOf and the required property to mark that it is expected that either one property or another is present

Example endpoint definition showing the issue:

PATCH /gists/{gist_id}

"gists/update": {
   [ ... ]
    requestBody: {
      content: {
        "application/json":
          | ({
              [ ... ]
              files?: {
                [key: string]:
                  | (
                      | ({
                          /** @description The new content of the file. */
                          content?: string;
                          /** @description The new filename for the file. */
                          filename?: string | null;
                        } & (
                          | Record<string, never>
                          | Record<string, never>
                          | Record<string, never>
                        ))
                      | null
                    )
                  | undefined;
              };
            } & (Record<string, never> | Record<string, never>))
          | null;
      };
    };
  };
"/gists/{gist_id}": {
[ ... ]
"patch": {
       [ ... ]
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                   [ ... ]
                  "files": {
                    [ ... ]
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "content": {
                          "description": "The new content of the file.",
                          "type": "string"
                        },
                        "filename": {
                          "description": "The new filename for the file.",
                          "type": "string",
                          "nullable": true
                        }
                      },
                      "anyOf": [
                        {
                          "required": [
                            "content"
                          ]
                        },
                        {
                          "required": [
                            "filename"
                          ]
                        },
                        {
                          "type": "object",
                          "maxProperties": 0
                        }
                      ]
                    }
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "description"
                    ]
                  },
                  {
                    "required": [
                      "files"
                    ]
                  }
                ],
                "type": "object",
                "nullable": true
              },
            [ ... ]
              }
            }
          }
        },
  [ ... ]
      },

Expected

For those anyOf not to exist.
Instead, there should be 2 definitions wrapped in a oneOf each with one of the properties that is expected at a time.

Reproduction Steps

N/A

See octokit/types.ts#534

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