Skip to content

Commit 716e64c

Browse files
committed
preserve inner generic type for Map<String, List<T>> deserialization
1 parent 701d1f5 commit 716e64c

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class {{{classname}}} {
163163
: {{items.complexType}}.mapListFromJson(json[r'{{{baseName}}}']),
164164
{{/items.complexType}}
165165
{{^items.complexType}}
166-
: mapCastOfType<String, List>(json, r'{{{baseName}}}'),
166+
: (json[r'{{{baseName}}}'] as Map<String, dynamic>).map((k, v) => MapEntry(k, v == null ? {{#items.isNullable}}null{{/items.isNullable}}{{^items.isNullable}}const <{{items.items.dataType}}>[]{{/items.isNullable}} : (v as List).cast<{{items.items.dataType}}>())),
167167
{{/items.complexType}}
168168
{{/items.isArray}}
169169
{{^items.isArray}}

modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,12 @@ components:
17311731
type: object
17321732
additionalProperties:
17331733
type: string
1734+
map_of_array_integer:
1735+
type: object
1736+
additionalProperties:
1737+
type: array
1738+
items:
1739+
type: integer
17341740
MixedPropertiesAndAdditionalPropertiesClass:
17351741
type: object
17361742
properties:

samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/AdditionalPropertiesClass.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Name | Type | Description | Notes
1010
------------ | ------------- | ------------- | -------------
1111
**mapProperty** | **Map<String, String>** | | [optional] [default to const {}]
1212
**mapOfMapProperty** | [**Map<String, Map<String, String>>**](Map.md) | | [optional] [default to const {}]
13+
**mapOfArrayInteger** | [**Map<String, List<int>>**](List.md) | | [optional] [default to const {}]
1314

1415
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1516

samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/additional_properties_class.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,36 @@ class AdditionalPropertiesClass {
1515
AdditionalPropertiesClass({
1616
this.mapProperty = const {},
1717
this.mapOfMapProperty = const {},
18+
this.mapOfArrayInteger = const {},
1819
});
1920

2021
Map<String, String> mapProperty;
2122

2223
Map<String, Map<String, String>> mapOfMapProperty;
2324

25+
Map<String, List<int>> mapOfArrayInteger;
26+
2427
@override
2528
bool operator ==(Object other) => identical(this, other) || other is AdditionalPropertiesClass &&
2629
_deepEquality.equals(other.mapProperty, mapProperty) &&
27-
_deepEquality.equals(other.mapOfMapProperty, mapOfMapProperty);
30+
_deepEquality.equals(other.mapOfMapProperty, mapOfMapProperty) &&
31+
_deepEquality.equals(other.mapOfArrayInteger, mapOfArrayInteger);
2832

2933
@override
3034
int get hashCode =>
3135
// ignore: unnecessary_parenthesis
3236
(mapProperty.hashCode) +
33-
(mapOfMapProperty.hashCode);
37+
(mapOfMapProperty.hashCode) +
38+
(mapOfArrayInteger.hashCode);
3439

3540
@override
36-
String toString() => 'AdditionalPropertiesClass[mapProperty=$mapProperty, mapOfMapProperty=$mapOfMapProperty]';
41+
String toString() => 'AdditionalPropertiesClass[mapProperty=$mapProperty, mapOfMapProperty=$mapOfMapProperty, mapOfArrayInteger=$mapOfArrayInteger]';
3742

3843
Map<String, dynamic> toJson() {
3944
final json = <String, dynamic>{};
4045
json[r'map_property'] = this.mapProperty;
4146
json[r'map_of_map_property'] = this.mapOfMapProperty;
47+
json[r'map_of_array_integer'] = this.mapOfArrayInteger;
4248
return json;
4349
}
4450

@@ -63,6 +69,9 @@ class AdditionalPropertiesClass {
6369
return AdditionalPropertiesClass(
6470
mapProperty: mapCastOfType<String, String>(json, r'map_property') ?? const {},
6571
mapOfMapProperty: mapCastOfType<String, dynamic>(json, r'map_of_map_property') ?? const {},
72+
mapOfArrayInteger: json[r'map_of_array_integer'] == null
73+
? const {}
74+
: (json[r'map_of_array_integer'] as Map<String, dynamic>).map((k, v) => MapEntry(k, v == null ? const <int>[] : (v as List).cast<int>())),
6675
);
6776
}
6877
return null;

0 commit comments

Comments
 (0)