A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/OpenAPITools/openapi-generator/issues/2567 below:

[BUG][Dart] Syntax error when generating array of arrays · Issue #2567 · OpenAPITools/openapi-generator · GitHub

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']);
    }
  }
`

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4