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] Map.mapFromJson is generated, but there's no such method on map. #8029

Open
3 of 6 tasks
Grohden opened this issue Nov 26, 2020 · 1 comment
Open
3 of 6 tasks

Comments

@Grohden
Copy link
Contributor

Grohden commented Nov 26, 2020

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 😆 (😢)

@auto-labeler
Copy link

auto-labeler bot commented Nov 26, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

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