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

Does not generate correct union for anyOf #819

Closed
jonaslagoni opened this issue Jul 27, 2022 · 1 comment
Closed

Does not generate correct union for anyOf #819

jonaslagoni opened this issue Jul 27, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@jonaslagoni
Copy link
Member

jonaslagoni commented Jul 27, 2022

Describe the bug

Related to next branch.

Following input:

{
  "type": "object",
  "definitions": {
    "icon": {
      "type": "string"
    }
  },
  "properties": {
      "default_icon": {
          "anyOf": [
              {
                  "type": "string",
                  "description": "FIXME: String form is deprecated."
              },
              {
                  "type": "object",
                  "description": "Icon for the main toolbar.",
                  "properties": {
                      "19": {
                          "$ref": "#/definitions/icon"
                      },
                      "38": {
                          "$ref": "#/definitions/icon"
                      }
                  }
              }
          ]
      }
  }
}

Expected behavior

Generates a model where only an object is possible, and not string.

This problem occurs as part of draft-4 chrome-manifest.json blackbox test.

@jonaslagoni
Copy link
Member Author

Seems to be fixed by #899 as it generates:

class Root {
  private _defaultIcon?: string | DefaultIconAnyOf_1;
  private _additionalProperties?: Map<string, any>;

  constructor(input: {
    defaultIcon?: string | DefaultIconAnyOf_1,
    additionalProperties?: Map<string, any>,
  }) {
    this._defaultIcon = input.defaultIcon;
    this._additionalProperties = input.additionalProperties;
  }

  get defaultIcon(): string | DefaultIconAnyOf_1 | undefined { return this._defaultIcon; }
  set defaultIcon(defaultIcon: string | DefaultIconAnyOf_1 | undefined) { this._defaultIcon = defaultIcon; }

  get additionalProperties(): Map<string, any> | undefined { return this._additionalProperties; }
  set additionalProperties(additionalProperties: Map<string, any> | undefined) { this._additionalProperties = additionalProperties; }
}
class DefaultIconAnyOf_1 {
  private _number_19?: string;
  private _number_38?: string;
  private _additionalProperties?: Map<string, any>;

  constructor(input: {
    number_19?: string,
    number_38?: string,
    additionalProperties?: Map<string, any>,
  }) {
    this._number_19 = input.number_19;
    this._number_38 = input.number_38;
    this._additionalProperties = input.additionalProperties;
  }

  get number_19(): string | undefined { return this._number_19; }
  set number_19(number_19: string | undefined) { this._number_19 = number_19; }

  get number_38(): string | undefined { return this._number_38; }
  set number_38(number_38: string | undefined) { this._number_38 = number_38; }

  get additionalProperties(): Map<string, any> | undefined { return this._additionalProperties; }
  set additionalProperties(additionalProperties: Map<string, any> | undefined) { this._additionalProperties = additionalProperties; }
}

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

No branches or pull requests

1 participant