forked from loafle/openapi-generator-original
Encode a Set
in toJson()
properly (#15435)
* Convert `Set` to `List` in `toJson()` for properly encoding a set. * Generate samples code. * Convert to List before encoding in `toJson()`. * Add `!` for nullable properties.
This commit is contained in:
parent
e152799569
commit
c84b949df1
@ -176,7 +176,7 @@ class {{{classname}}} {
|
||||
final responseBody = await _decodeBodyBytes(response);
|
||||
return (await apiClient.deserializeAsync(responseBody, '{{{returnType}}}') as List)
|
||||
.cast<{{{returnBaseType}}}>()
|
||||
.{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(){{/uniqueItems}};
|
||||
.{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}};
|
||||
{{/isArray}}
|
||||
{{^isArray}}
|
||||
{{#isMap}}
|
||||
|
@ -86,7 +86,7 @@ class {{{classname}}} {
|
||||
{{/isDate}}
|
||||
{{^isDateTime}}
|
||||
{{^isDate}}
|
||||
json[r'{{{baseName}}}'] = this.{{{name}}};
|
||||
json[r'{{{baseName}}}'] = this.{{{name}}}{{#isArray}}{{#uniqueItems}}{{#isNullable}}!{{/isNullable}}.toList(growable: false){{/uniqueItems}}{{/isArray}};
|
||||
{{/isDate}}
|
||||
{{/isDateTime}}
|
||||
{{#isNullable}}
|
||||
@ -200,8 +200,8 @@ class {{{classname}}} {
|
||||
{{{name}}}: {{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']){{#uniqueItems}}.toSet(){{/uniqueItems}},
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{{name}}}: json[r'{{{baseName}}}'] is {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}}
|
||||
? (json[r'{{{baseName}}}'] as {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}}).cast<{{{items.datatype}}}>()
|
||||
{{{name}}}: json[r'{{{baseName}}}'] is Iterable
|
||||
? (json[r'{{{baseName}}}'] as Iterable).cast<{{{items.datatype}}}>().{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}}
|
||||
: {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}},
|
||||
{{/isEnum}}
|
||||
{{/isArray}}
|
||||
|
@ -190,7 +190,7 @@ class PetApi {
|
||||
final responseBody = await _decodeBodyBytes(response);
|
||||
return (await apiClient.deserializeAsync(responseBody, 'List<Pet>') as List)
|
||||
.cast<Pet>()
|
||||
.toList();
|
||||
.toList(growable: false);
|
||||
|
||||
}
|
||||
return null;
|
||||
@ -253,7 +253,7 @@ class PetApi {
|
||||
final responseBody = await _decodeBodyBytes(response);
|
||||
return (await apiClient.deserializeAsync(responseBody, 'List<Pet>') as List)
|
||||
.cast<Pet>()
|
||||
.toList();
|
||||
.toList(growable: false);
|
||||
|
||||
}
|
||||
return null;
|
||||
|
@ -113,8 +113,8 @@ class Pet {
|
||||
id: mapValueOfType<int>(json, r'id'),
|
||||
category: Category.fromJson(json[r'category']),
|
||||
name: mapValueOfType<String>(json, r'name')!,
|
||||
photoUrls: json[r'photoUrls'] is List
|
||||
? (json[r'photoUrls'] as List).cast<String>()
|
||||
photoUrls: json[r'photoUrls'] is Iterable
|
||||
? (json[r'photoUrls'] as Iterable).cast<String>().toList(growable: false)
|
||||
: const [],
|
||||
tags: Tag.listFromJson(json[r'tags']),
|
||||
status: PetStatusEnum.fromJson(json[r'status']),
|
||||
|
@ -182,7 +182,7 @@ class PetApi {
|
||||
final responseBody = await _decodeBodyBytes(response);
|
||||
return (await apiClient.deserializeAsync(responseBody, 'List<Pet>') as List)
|
||||
.cast<Pet>()
|
||||
.toList();
|
||||
.toList(growable: false);
|
||||
|
||||
}
|
||||
return null;
|
||||
|
@ -55,8 +55,8 @@ class ArrayOfNumberOnly {
|
||||
}());
|
||||
|
||||
return ArrayOfNumberOnly(
|
||||
arrayNumber: json[r'ArrayNumber'] is List
|
||||
? (json[r'ArrayNumber'] as List).cast<num>()
|
||||
arrayNumber: json[r'ArrayNumber'] is Iterable
|
||||
? (json[r'ArrayNumber'] as Iterable).cast<num>().toList(growable: false)
|
||||
: const [],
|
||||
);
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ class ArrayTest {
|
||||
}());
|
||||
|
||||
return ArrayTest(
|
||||
arrayOfString: json[r'array_of_string'] is List
|
||||
? (json[r'array_of_string'] as List).cast<String>()
|
||||
arrayOfString: json[r'array_of_string'] is Iterable
|
||||
? (json[r'array_of_string'] as Iterable).cast<String>().toList(growable: false)
|
||||
: const [],
|
||||
arrayArrayOfInteger: json[r'array_array_of_integer'] is List
|
||||
? (json[r'array_array_of_integer'] as List).map((e) =>
|
||||
|
@ -108,8 +108,8 @@ class ObjectWithDeprecatedFields {
|
||||
? null
|
||||
: num.parse(json[r'id'].toString()),
|
||||
deprecatedRef: DeprecatedObject.fromJson(json[r'deprecatedRef']),
|
||||
bars: json[r'bars'] is List
|
||||
? (json[r'bars'] as List).cast<String>()
|
||||
bars: json[r'bars'] is Iterable
|
||||
? (json[r'bars'] as Iterable).cast<String>().toList(growable: false)
|
||||
: const [],
|
||||
);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class Pet {
|
||||
json[r'category'] = null;
|
||||
}
|
||||
json[r'name'] = this.name;
|
||||
json[r'photoUrls'] = this.photoUrls;
|
||||
json[r'photoUrls'] = this.photoUrls.toList(growable: false);
|
||||
json[r'tags'] = this.tags;
|
||||
if (this.status != null) {
|
||||
json[r'status'] = this.status;
|
||||
@ -113,8 +113,8 @@ class Pet {
|
||||
id: mapValueOfType<int>(json, r'id'),
|
||||
category: Category.fromJson(json[r'category']),
|
||||
name: mapValueOfType<String>(json, r'name')!,
|
||||
photoUrls: json[r'photoUrls'] is Set
|
||||
? (json[r'photoUrls'] as Set).cast<String>()
|
||||
photoUrls: json[r'photoUrls'] is Iterable
|
||||
? (json[r'photoUrls'] as Iterable).cast<String>().toSet()
|
||||
: const {},
|
||||
tags: Tag.listFromJson(json[r'tags']),
|
||||
status: PetStatusEnum.fromJson(json[r'status']),
|
||||
|
Loading…
x
Reference in New Issue
Block a user