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] Error: Member not found: 'Object.listFromJson'. #20152

Open
3 of 6 tasks
Roth-EAD opened this issue Nov 21, 2024 · 0 comments
Open
3 of 6 tasks

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

Roth-EAD opened this issue Nov 21, 2024 · 0 comments

Comments

@Roth-EAD
Copy link

Roth-EAD commented Nov 21, 2024

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

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

No branches or pull requests

1 participant