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

The @discriminator tag does not handle ref type discriminators #1718

Open
PLkolek opened this issue Jul 9, 2023 · 0 comments
Open

The @discriminator tag does not handle ref type discriminators #1718

PLkolek opened this issue Jul 9, 2023 · 0 comments

Comments

@PLkolek
Copy link

PLkolek commented Jul 9, 2023

Very similar (hence I copied the description and just substituted inputs and outputs) issue to #1682, but now caused by using an exported type as a discriminator.

For example,

export enum AEnum {
    a = "a",
    A = "A"
}

type A = { kind: AEnum, a: string }
type B = { kind: "b" | "B", b: string }

/**
 * @discriminator kind
 */
export type AB = A | B;

results in the following schema for the type AB:

Schema result
{
  "$id": "api.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "AB": {
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "$ref": "#/definitions/AEnum"
              }
            }
          },
          "then": {
            "additionalProperties": false,
            "properties": {
              "a": {
                "type": "string"
              },
              "kind": {
                "$ref": "#/definitions/AEnum"
              }
            },
            "required": [
              "kind",
              "a"
            ],
            "type": "object"
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "enum": [
                  "b",
                  "B"
                ],
                "type": "string"
              }
            }
          },
          "then": {
            "additionalProperties": false,
            "properties": {
              "b": {
                "type": "string"
              },
              "kind": {
                "enum": [
                  "b",
                  "B"
                ],
                "type": "string"
              }
            },
            "required": [
              "kind",
              "b"
            ],
            "type": "object"
          }
        }
      ],
      "properties": {
        "kind": {
          "enum": [
            "b",
            "B"
          ]
        }
      },
      "required": [
        "kind"
      ],
      "type": "object"
    },
    "AEnum": {
      "enum": [
        "a",
        "A"
      ],
      "type": "string"
    }
  }
}

Where the set of accepted values for the outermost kind enum is does not contain the values originating from AEnum, whereas it should list all possible options.

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