Skip to content

Two-dimensional arrays not handled? #46

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

Closed
scvnathan opened this issue Aug 6, 2019 · 4 comments · Fixed by #54
Closed

Two-dimensional arrays not handled? #46

scvnathan opened this issue Aug 6, 2019 · 4 comments · Fixed by #54

Comments

@scvnathan
Copy link
Contributor

scvnathan commented Aug 6, 2019

Hi, it looks like two-dimensional arrays are not being handled, which I noticed in my own project but I've replicated the behavior here by modifying example/input.yaml:

  Provider:
    type: object
    properties:
      id: { $ref: '#/definitions/ID' }
      version: { type: integer, enum: [1] }
      type: { type: string, enum: ['provider'] }
      body: { $ref: '#/definitions/ProviderBody' }
      twoDimArray:
        type: array
        items:
          type: array
          items: { $ref: '#/definitions/ProviderBody' }
    additionalProperties: false
    required:
      - id
      - version
      - type
      - body

I would expect the generated type to be:

export interface Provider {
  id: string;
  version: 1;
  type: 'provider';
  body: ProviderBody;
  twoDimArray?: ProviderBody[][];
}

But it ends up generating this:

export interface Provider {
  id: string;
  version: 1;
  type: 'provider';
  body: ProviderBody;
  twoDimArray?: ProviderTwoDimArray[];
}
export interface ProviderTwoDimArray {}

Does this look like a valid bug?
Thanks

@drwpow
Copy link
Contributor

drwpow commented Aug 28, 2019

Ah yup! This is a bug. Sorry for the delay. I’ll add a PR & a test to catch this right away. Sorry for the inconvenience!

@drwpow
Copy link
Contributor

drwpow commented Aug 28, 2019

@scvnathan could you try the latest version? Using npx should pull the latest version now, or update to 1.3.1 if running locally.

@drwpow
Copy link
Contributor

drwpow commented Aug 28, 2019

I even added a test for catching nested nested arrays so we should be good 😛

environments:
  type: "array"
  items:
    type: "array"
    items:
      type: "array"
      items: { type: "string" }

should generate to:

environments?: string[][][];

@scvnathan
Copy link
Contributor Author

Hey thanks @DangoDev, nice job! I'll test this out again today

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

Successfully merging a pull request may close this issue.

2 participants