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] "The method 'listFromJson' isn't defiend" for DateTime #11462

Open
5 of 6 tasks
jhlgns opened this issue Jan 30, 2022 · 5 comments
Open
5 of 6 tasks

[BUG] [Dart] "The method 'listFromJson' isn't defiend" for DateTime #11462

jhlgns opened this issue Jan 30, 2022 · 5 comments

Comments

@jhlgns
Copy link

jhlgns commented Jan 30, 2022

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

When using the generated Dart code, this error get's displayed:

The method 'listFromJson' isn't defined for the type 'DateTime'.
Try correcting the name to the name of an existing method, or defining a method named 'listFromJson'.
openapi-generator version

openapi-generator-cli 5.4.0-SNAPSHOT
commit : 35fea62
built : 2022-01-29T18:29:19Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/

OpenAPI declaration file content or url

https://api.apaleo.com/swagger/inventory-v1/swagger.json

Generation Details

n/a

Steps to reproduce
  • docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate -i /local/swagger.json -g dart -o /local/api
  • Use the generated dart library
Related issues/PRs

n/a

Suggest a fix

I don't know the internals of OpenAPITools - probably the listFromJson implementation for builtin types needs to be fixed?

@jhlgns
Copy link
Author

jhlgns commented Feb 3, 2022

Just tested this with a 6.0.0 snapshot, docker container was built directly from master, still persists.

@hey-nicolasklein
Copy link

I have a similliar problem with MultipartFile:

../openapi/lib/model/file_list.dart:55:30: Error: Member not found: 'MultipartFile.listFromJson'.
            files: MultipartFile.listFromJson(json[r'files']),

@aeneasr
Copy link
Contributor

aeneasr commented Jul 28, 2022

We also experience this issue with 6.0.1. Is this related to: #4887 ?

@jtmuller5
Copy link

jtmuller5 commented Sep 15, 2022

You can't create static extension methods for built-in Dart classes: dart-lang/language#723

Until that is possible, you can create an extension for the DateTime class like this:

extension DateTimeHelper on DateTime {
  
  static List<DateTime>? listFromJson(dynamic json, {bool growable = false}) {
    final result = <DateTime>[];
    if (json is List && json.isNotEmpty) {
      for (final row in json) {
        final value = DateTime.tryParse(row);
        if (value != null) {
          result.add(value);
        }
      }
    }
    return result.toList(growable: growable);
  }
}

And then call the extension method using hte name of the extension:

DateTimeHelper.listFromJson()

@ozialien
Copy link
Contributor

Seems to happen in typescript fetch for some spring generated swagger specs.

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

5 participants