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

RegExp types are now emitted, breaking schema validation (v2.1.1) #1945

Open
Jason3S opened this issue May 3, 2024 · 1 comment
Open

RegExp types are now emitted, breaking schema validation (v2.1.1) #1945

Jason3S opened this issue May 3, 2024 · 1 comment

Comments

@Jason3S
Copy link
Contributor

Jason3S commented May 3, 2024

Related to: #1921, #1927, and #1930

With the release of 2.1.0, I started seeing schema validation errors.

Below is an example where a field in an interface could be a string or a RegExp. Before 2.1, this worked because the generated just dropped the RegExp class.

Given the following interface:

export interface PatternAdjustment {
    /** Id of the Adjustment, i.e. `short-compound` */
    id: string;
    /** RegExp pattern to match */
    regexp: string | RegExp;
    /** The amount of penalty to apply. */
    penalty: number;
}

Output: v2.1.1

    "PatternAdjustment": {
      "additionalProperties": false,
      "properties": {
        "id": {
          "description": "Id of the Adjustment, i.e. `short-compound`",
          "markdownDescription": "Id of the Adjustment, i.e. `short-compound`",
          "type": "string"
        },
        "penalty": {
          "description": "The amount of penalty to apply.",
          "markdownDescription": "The amount of penalty to apply.",
          "type": "number"
        },
        "regexp": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "format": "regex", <-- Unknown format
              "type": "string"
            }
          ],
          "description": "RegExp pattern to match",
          "markdownDescription": "RegExp pattern to match"
        }
      },
      "required": [
        "id",
        "regexp",
        "penalty"
      ],
      "type": "object"
    },

Output: v2.0.1

    "PatternAdjustment": {
      "additionalProperties": false,
      "properties": {
        "id": {
          "description": "Id of the Adjustment, i.e. `short-compound`",
          "markdownDescription": "Id of the Adjustment, i.e. `short-compound`",
          "type": "string"
        },
        "penalty": {
          "description": "The amount of penalty to apply.",
          "markdownDescription": "The amount of penalty to apply.",
          "type": "number"
        },
        "regexp": {
          "description": "RegExp pattern to match",
          "markdownDescription": "RegExp pattern to match",
          "type": "string"
        }
      },
      "required": [
        "id",
        "regexp",
        "penalty"
      ],
      "type": "object"
    },

I'm going to try to work around this by creating a new type and using @hidden.

@domoritz
Copy link
Member

domoritz commented May 3, 2024

What if you just have a regex?

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

3 participants