openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open allenkaplan opened this issue 3 years ago • 1 comments

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [X] Have you validated the input using an OpenAPI validator (example)?
  • [X] Have you tested with the latest master to confirm the issue still exists?
  • [X] 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! https://github.com/OpenAPITools/openapi-generator/issues/8029 and https://github.com/OpenAPITools/openapi-generator/issues/12165

Suggest a fix

Not the most confident, but I think it will be a relatively simple fix of the moustache -- not sure why https://github.com/OpenAPITools/openapi-generator/pull/12426 didn't find the issue given the spec in the PR

allenkaplan avatar Jul 18 '22 21:07 allenkaplan

I think my PR #12574 fixed this.

jeffmikels avatar Oct 10 '22 16:10 jeffmikels