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

spuriously duplicated types may be generated #487

Open
ahl opened this issue Jan 20, 2024 · 0 comments
Open

spuriously duplicated types may be generated #487

ahl opened this issue Jan 20, 2024 · 0 comments

Comments

@ahl
Copy link
Collaborator

ahl commented Jan 20, 2024

Consider this case (roughly) from the checked in github.json data:

    "issue_comment$deleted": {
      "$schema": "http://json-schema.org/draft-07/schema",
      "type": "object",
      "required": ["action", "issue", "comment", "repository", "sender"],
      "properties": {
        "action": { "type": "string", "enum": ["deleted"] },
        "issue": {
          "description": "The [issue](https://docs.github.com/en/rest/reference/issues) the comment belongs to.",
          "allOf": [
            { "$ref": "#/definitions/issue" },
            {
              "type": "object",
              "required": ["labels", "state", "locked", "assignee"],
              "properties": {
                "assignee": {
                  "oneOf": [
                    { "$ref": "#/definitions/user" },
                    { "type": "null" }
                  ]
                },
...

In particular note issue and it's assignee property. In #/definitions/issue (think of it as the base class), assignee is defined like this:

        "assignee": {
          "oneOf": [{ "$ref": "#/definitions/user" }, { "type": "null" }]
        },

So... the same. We would expect the merge logic to try to merge these two (identical) oneOfs and come up with that same, identical oneOf. That's sometimes not what happens, in particular if the #/definitions/user type is sufficiently complex. In that case we get a type generated named IssueCommentDeletedIssueAssignee that is identical to the User type.

Here is a schema that reproduces the issue:

{
  "definitions": {
    "issue": {
      "type": "object",
      "required": [
        "assignee"
      ],
      "properties": {
        "assignee": {
          "oneOf": [
            {
              "$ref": "#/definitions/user"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "issue_comment$deleted": {
      "type": "object",
      "required": [
        "issue"
      ],
      "properties": {
        "issue": {
          "allOf": [
            {
              "$ref": "#/definitions/issue"
            },
            {
              "type": "object",
              "required": [
                "assignee"
              ],
              "properties": {
                "assignee": {
                  "oneOf": [
                    {
                      "$ref": "#/definitions/user"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    },
    "user": {
      "$schema": "http://json-schema.org/draft-07/schema",
      "type": "object",
      "properties": {
        "email": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}

Note that if we made #/definitions/user/properties/email/type into a simple type (e.g. "string") rather than a type array, we get the expected result.

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

No branches or pull requests

1 participant