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

[BUG][Dart] Syntax error when generating array of arrays #2567

Closed
Croptracker opened this issue Apr 1, 2019 · 2 comments · Fixed by #6913
Closed

[BUG][Dart] Syntax error when generating array of arrays #2567

Croptracker opened this issue Apr 1, 2019 · 2 comments · Fixed by #6913

Comments

@Croptracker
Copy link

Description

An OpenAPI spec that defines an array of arrays will generate Dart code with syntax errors.

openapi-generator version

4.0

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  version: "1"
  title: Dart Bug
  license:
    name: Proprietary
servers:
- url: 'http://petstore.swagger.io/v1'

paths:

  /bug/getArrayOfArrays:
    post:
      operationId: getArrayOfArrays
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ArrayOfArraysResponse'


components:
  schemas:

    ArrayOfArraysResponse:
      properties:
        payload:
          type: array
          items:
            type: array
            items:
              $ref: '#/components/schemas/MyObject'


    MyObject:
      properties:
        first_name:
          type: string
Command line used for generation

java -jar etc/openapi/openapi-generator-cli-4.0.jar generate -i array_of_arrays_bug.yaml -g dart -o lib/services -DSkiptests

Steps to reproduce

Run the Dart generator on the above OpenAPI spec. The generated ArrayOfArraysResponse object looks like:

  ArrayOfArraysResponse.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
    if (json['payload'] == null) {
      payload = null;
    } else {
      payload = List.listFromJson(json['payload']);
    }
  }

Which as the following error: Error: Method not found: 'List.listFromJson'.

The workaround is to make the following changes:

components:
  schemas:

    ArrayOfArraysResponse:
      properties:
        payload:
          type: array
          items:
            $ref: '#/components/schemas/Parent'

    Parent:
      properties:
        children:
          type: array
          items:
            $ref: '#/components/schemas/MyObject'

    MyObject:
      properties:
        first_name:
          type: string

Which then correctly generates:

  ArrayOfArraysResponse.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
    if (json['payload'] == null) {
      payload = null;
    } else {
      payload = Parent.listFromJson(json['payload']);
    }
  }
`
@auto-labeler
Copy link

auto-labeler bot commented Apr 1, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@lukepighetti
Copy link

This issue still exists today, creating new ticket here: #12305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants