Skip to content

[BUG][Dart] Map.mapFromJson is generated, but there's no such method on map. #8029

Open
@Grohden

Description

@Grohden

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

Dart generator may have a problem dealing with a Map of Maps (something like Map<String, Map<String>>), here's a screenshot from a generated code:

image

There's no such thing as Map.mapFromJson (at least I couldn't find it in dart 1 or 2 docs), so maybe there's a problem with the generator template.

openapi-generator version

5.0.0-beta3

OpenAPI declaration file content or url

https://gist.github.com/Grohden/13d012470a9860f3dc26c219c4674361

Steps to reproduce

Download the gist json, and run:

java -jar ./openapi-generator-cli.jar generate -g dart -i ./test.json -o ./api
Related issues/PRs

Probably #7850 (?)

Suggest a fix

The problem may be here:

{{{name}}}: json['{{{baseName}}}'] == null
? null
: {{{complexType}}}.mapFromJson(json['{{{baseName}}}']),
{{/items.isArray}}

I've removed the mapFromJson call from my template (copied today from the master) and I haven't found any issues with the dart analyzer.. but I haven't tested it in runtime either, so I'm not sure.

Another way to fix it could be to add the mapFromJson as an extension method for maps.. but I'm not sure how it would work

Fun fact (?): I've copied all the dart generator sources, converted them to kotlin and generated a client just to see if could fix the issue.. but the project is too complex for me to understand how/where that Map was generated, and I found out that some of my problems were solved yesterday on the templates 😆 (😢)

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