Skip to content

Conversation

@EddieRydell
Copy link

@EddieRydell EddieRydell commented Jan 17, 2026

Fixes #19997

When generating Dart code for Map<String, List<T>> properties (e.g., Map<String, List<int>>), the fromJson deserialization was losing the inner generic type:

Previous code:

calendar: mapCastOfType<String, List>(json, r'calendar'),
// Results in Map<String, List<dynamic>> - inner type lost

Fixed code:

calendar: (json[r'calendar'] as Map<String, dynamic>).map(
  (k, v) => MapEntry(k, v == null ? const <T>[] : (v as List).cast<T>())),
  // Inner type T preserved

Changes

  • Updated native_class.mustache template to properly cast inner List types
  • Added map_of_array_integer test property to AdditionalPropertiesClass in the Dart petstore spec

Summary by cubic

Preserves the inner generic type when deserializing Map<String, List> in generated Dart models, preventing List in values. Fixes #19997 and ensures correct typing (e.g., Map<String, List>).

  • Bug Fixes
    • Updated dart2 native_class.mustache to map and cast list values (v as List).cast(), with null-safe defaults (empty list or null when nullable).
    • Added map_of_array_integer to the petstore spec to cover Map<String, List> and updated the generated model and docs.

Written for commit 716e64c. Summary will update on new commits.

@EddieRydell EddieRydell marked this pull request as ready for review January 17, 2026 18:53
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache:166">
P2: Map<String, List<Enum>> deserialization now casts lists to the enum type without converting JSON strings, causing a runtime TypeError for enum values.</violation>
</file>

<file name="samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/additional_properties_class.dart">

<violation number="1" location="samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/additional_properties_class.dart:38">
P2: hashCode uses map identity while == uses deep equality for mapOfArrayInteger, breaking equality contract</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant