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

Unions are generate incorrect with arrays #914

Closed
jonaslagoni opened this issue Sep 29, 2022 · 0 comments · Fixed by #928
Closed

Unions are generate incorrect with arrays #914

jonaslagoni opened this issue Sep 29, 2022 · 0 comments · Fixed by #928
Labels
bug Something isn't working

Comments

@jonaslagoni
Copy link
Member

Describe the bug

Given the following JSON schema input:

const jsonSchemaDraft7 = {
  $schema: 'http://json-schema.org/draft-07/schema#',
  type: 'object',
  additionalProperties: false,
  properties: {
    email: {
      anyOf: [
        {
          type: 'string'
        },
        {
          type: 'array',
          items: {
            type: 'number'
          }
        }
      ]
    }
  }
};

Generate the following TypeScript model:

class Root {
  private _email?: string | number | any[];

  constructor(input: {
    email?: string | number | any[],
  }) {
    this._email = input.email;
  }

  get email(): string | number | any[] | undefined { return this._email; }
  set email(email: string | number | any[] | undefined) { this._email = email; }
}

Looks like the schema for the array and the array items schema are somehow interpreted as two separate things.

Expected behavior

Expected the class to be:

class Root {
  private _email?: string | number[];

  constructor(input: {
    email?: string | number[],
  }) {
    this._email = input.email;
  }

  get email(): string | number[] | undefined { return this._email; }
  set email(email: string | number[] | undefined) { this._email = email; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant