Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wolfy1339 opened this issue Apr 28, 2023 · 0 comments

Comments

@wolfy1339
Copy link

wolfy1339 commented Apr 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants