swagger-api / swagger-api/swagger-codegen

[Dart] Unable to generate fromJson method for list of date time

Open
#9,440 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

If the swagger response contains a list of DateTime objects, It generates the wrong method for parsing from JSON.

For example for the below JSON:

{
  "dates" : [ ... ]
}

It generates:

 MyDto.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
    dates =
      DateTime.listFromJson(json['dates']);
  }

So, the DateTime has no listFromJson method.

I'm using the online editor to generate dart client code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in the online editor and inspect the generated Dart deserialization for a list of DateTime values. Trace the generator template or entry point responsible for this output; done means the generated fromJson method uses a valid way to parse the dates list without calling DateTime.listFromJson.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.