Skip to content

[BUG][Dart] Error: Member not found: 'Object.listFromJson'. #20152

@roth-arasys

Description

@roth-arasys

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)

Description

Issue:
When generating fromJson in native_class.mustache has a complexType "Object" (happens when a Schema has a List), then you will get the Error: Error: Member not found: 'Object.listFromJson' within the fromJson of the Model.
grafik

Suggestion:
Change Line:
{{{name}}}: {{{complexType}}}.listFromJson(json[r'{{{baseName}}}']){{#uniqueItems}}.toSet(){{/uniqueItems}},
With Lines:

                {{#items.complexType}}
        {{{name}}}: {{{complexType}}}.listFromJson(json[r'{{{baseName}}}']){{#uniqueItems}}.toSet(){{/uniqueItems}},
                {{/items.complexType}}
                {{^items.complexType}}
        {{{name}}}: (json[r'{{{baseName}}}'] as List).map((e) => e as {{{complexType}}}){{#uniqueItems}}.toSet(){{/uniqueItems}}{{^uniqueItems}}.toList(){{/uniqueItems}},
                {{/items.complexType}}
openapi-generator version

7.10.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "components": {
    "schemas": {
      "Test": {
        "required": [
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "values": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  }
}
Steps to reproduce

docker-compose.yml:

services:
  openapi-dart-generator:
    image: openapitools/openapi-generator-cli:latest
    volumes:
      - .:/workspace
    working_dir: /workspace
    command: [
      "generate",
      "-i", "/workspace/test.json",
      "-g", "dart",
      "-o", "/workspace/output/v1",
      "--additional-properties", "pubName=api_client",
      "--skip-validate-spec",
#      "-t", "/workspace/custom-templates"
    ]

Run: docker-compose up

Import Output into PubSpec:

  api_client:
    path: \OpenAPI\output\v1

Use Import in main.dart:
import 'package:api_client/api.dart';

Run Flutter and this Error:
grafik

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions