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

Trouble with generating an array of number enums #9

Closed
morbalint opened this issue Nov 26, 2018 · 7 comments
Closed

Trouble with generating an array of number enums #9

morbalint opened this issue Nov 26, 2018 · 7 comments

Comments

@morbalint
Copy link
Contributor

morbalint commented Nov 26, 2018

The generator removes an array from the swagger.json schema when the array contains a number enum.
simplified example:

{ 
  "definitions": {
    "MyModel": {
      "type":"object",
      "properties": {
          "foo": {
          "uniqueItems": true,
          "type": "array",
          "items": {
            "format": "int32",
            "enum": [
              0,
              1,
              2,
              4,
              8
            ],
            "type": "integer"
          }
        },
      }
    }
  }
}

the generated class will look something like this:

export class MyModel {
  foo: 0 | 1 | 2 | 4 | 8;
  constructor(data?: any) {
    if (data) {
      this['foo'] = data['foo'];
    }
  }
}

Sorry for the low quality example :(

I believe, I have found the error, and I will create a PR later.

Can you confirm its still an issue in your latest development branch ?

@Manweill
Copy link
Owner

Sure, I will confirm it

@Manweill
Copy link
Owner

I fix it ,it will generate like this:

type INumberArrayEnumModelFoo = 0 | 1 | 2 | 4 | 8;

export class NumberArrayEnumModel {
  /**  */
  foo: INumberArrayEnumModelFoo[]

  constructor(data?: any) {
    if (data) {
      this['foo'] = data['foo'];
    }
  }
}

@morbalint
Copy link
Contributor Author

Thank you!

@Manweill
Copy link
Owner

You are welcome!
Thank you for your interest in this library and application to the actual project.

@morbalint
Copy link
Contributor Author

Hi!

I tried, your fix and found an error with it. When you have more than one number enum, the generator does not separate the types and creates file with wrong syntax.

Created pull request with example to show, and a fix.

Should, this be a separate issue, or can we track it in this one?

Also, what is your release process, should I increase the version number and add the issue to the changelog ?

@Manweill
Copy link
Owner

Manweill commented Nov 27, 2018

I reopen this issue.
When i publish, I will test the example with the generator.
If the test passes, add the issue to the changelog and increase the version

@Manweill Manweill reopened this Nov 27, 2018
@Manweill
Copy link
Owner

@morbalint
The PR #11 need me publish now?

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

2 participants