OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.98k stars 6.6k forks source link

[BUG] [Dart] Map<String,List<int>> wrong deserialization #19997

Open escamoteur opened 3 weeks ago

escamoteur commented 3 weeks ago
Description

this open-api spech part:

      "CollectionCalendarDto": {
        "type": "object",
        "properties": {
          "calendar": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          },

generates correctly the property

  Map<String, List<int>> calendar;

but the fromJson method is wrong:

      return CollectionCalendarDto(
        calendar: json[r'calendar'] == null
            ? const {}
            : mapCastOfType<String, List>(json, r'calendar'),
        mostWornWatch: WatchTinyDto.fromJson(json[r'most_worn_watch']),
      );

the int is missing and as this is a required type it should have a trailing !

openapi-generator version
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
escamoteur commented 6 days ago

ok it turns out this sort of deep cast doesn't work see https://forum.itsallwidgets.com/t/problem-casting-json-propert-to-map-string-list-int/738/7?u=escamoteur

the correct line that would work is:

      return CollectionCalendarDto(
        calendar: json[r'calendar'] == null
            ? const {}
            : (json['calendar'] as Map<String, dynamic>).map(
                (key, value) => MapEntry(key, (value as List).cast<int>())),