Skip to content

[BUG] [Dart] additional properties: fromJson with field of type List<Map<String, Object>> does not generate correctly #12914

Open
@allenkaplan

Description

@allenkaplan

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

Incorrect code generation from spec leading to error when attempting to use generated dart code

currently details generates as type List<Map<String, Object>> but then tries to do return Foo(bar: Map.listFromJson(...)) ?? const[] in Foo fromJson(...){...} which throws build error as defined below

Expected details: (json[r'details'] as List).map((e) => e as Map<String, Object>).toList(),

openapi-generator version

6.0.1

OpenAPI declaration file content or url

Ran into an issue with Dart generation from api spec here

          "details": {
            "additionalProperties": true,
            "description": "Further error details",
            "type": "object"
          },

which generated from the OpenAPI Dart template here and the java generator here

details: Map.listFromJson(json[r'details']) ?? const [],

Understandably, since there is no listFromJson method for the native Map<K, V>, dart throws the following error on build

 Error: Member not found: 'Map.listFromJson'.
Generation Details
dart () {
  echo "Generating Dart..."

  dir="clients/${PROJECT}/dart"
  rm -rf "$dir" || true
  mkdir -p "$dir"

  openapi-generator-cli version-manager set 6.0.1
  openapi-generator-cli generate -i "${SPEC_FILE}" \
    -g dart \
    -o "$dir" \
    --git-user-id ory \
    --git-repo-id sdk \
    --git-host github.com \
    -c ./config/client/dart.yml.proc.yml

  cp "LICENSE" "clients/${PROJECT}/dart"
}
Steps to reproduce

Generate Ory SDK or any other other spec with addition properties for object

Related issues/PRs

Yes! #8029 and #12165

Suggest a fix

Not the most confident, but I think it will be a relatively simple fix of the moustache -- not sure why #12426 didn't find the issue given the spec in the PR

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