OpenAPITools / OpenAPITools/openapi-generator
[BUG][Dart] Map.mapFromJson is generated, but there's no such method on map.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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:

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:
https://github.com/OpenAPITools/openapi-generator/blob/4dc8d2a3514af15ac13624d4dc8e2e179749e5bd/modules/openapi-generator/src/main/resources/dart2/class.mustache#L149-L152
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 😆 (😢)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Dart generator template at modules/openapi-generator/src/main/resources/dart2/class.mustache around lines 149-152. Reproduce the issue using the linked gist and the provided java -jar generation command, then inspect the generated Map handling and run the Dart analyzer. Done means generated code no longer calls the nonexistent Map.mapFromJson method and still analyzes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100