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

Introduce changes necessary for Dart 3.0.0/Flutter 3.10.0 #15516

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ class ApiClient {
}
{{#native_serialization}}

Future<dynamic> deserializeAsync(String json, String targetType, {bool growable = false,}) async =>
Future<dynamic> deserializeAsync(String value, String targetType, {bool growable = false,}) async =>
// ignore: deprecated_member_use_from_same_package
deserialize(json, targetType, growable: growable);
deserialize(value, targetType, growable: growable);

@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use deserializeAsync() instead.')
dynamic deserialize(String json, String targetType, {bool growable = false,}) {
dynamic deserialize(String value, String targetType, {bool growable = false,}) {
// Remove all spaces. Necessary for regular expressions as well.
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments

// If the expected target type is String, nothing to do...
return targetType == 'String'
? json
: _deserialize(jsonDecode(json), targetType, growable: growable);
? value
: fromJson(json.decode(value), targetType, growable: growable);
}
{{/native_serialization}}

Expand All @@ -157,7 +157,8 @@ class ApiClient {
String serialize(Object? value) => value == null ? '' : json.encode(value);

{{#native_serialization}}
static dynamic _deserialize(dynamic value, String targetType, {bool growable = false}) {
/// Returns a native instance of an OpenAPI class matching the [specified type][targetType].
static dynamic fromJson(dynamic value, String targetType, {bool growable = false,}) {
try {
switch (targetType) {
case 'String':
Expand Down Expand Up @@ -189,18 +190,18 @@ class ApiClient {
dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toList(growable: growable);
}
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toSet();
}
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(),
value.values.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)),
value.values.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,)),
);
}
}
Expand Down Expand Up @@ -231,6 +232,17 @@ class DeserializationMessage {
final bool growable;
}

/// Primarily intended for use in an isolate.
Future<dynamic> decodeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well.
final targetType = message.targetType.replaceAll(' ', '');

// If the expected target type is String, nothing to do...
return targetType == 'String'
? message.json
: json.decode(message.json);
}

/// Primarily intended for use in an isolate.
Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well.
Expand All @@ -239,8 +251,8 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// If the expected target type is String, nothing to do...
return targetType == 'String'
? message.json
: ApiClient._deserialize(
jsonDecode(message.json),
: ApiClient.fromJson(
json.decode(message.json),
targetType,
growable: message.growable,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
http: '>=0.13.0 <0.14.0'
intl: '^0.17.0'
intl: '^0.18.0'
meta: '^1.1.8'
dev_dependencies:
test: '>=1.16.0 <1.18.0'
{{#json_serializable}}
build_runner: '^1.10.9'
json_serializable: '^3.5.1'{{/json_serializable}}
json_serializable: '^3.5.1'{{/json_serializable}}
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ class ApiClient {
);
}

Future<dynamic> deserializeAsync(String json, String targetType, {bool growable = false,}) async =>
Future<dynamic> deserializeAsync(String value, String targetType, {bool growable = false,}) async =>
// ignore: deprecated_member_use_from_same_package
deserialize(json, targetType, growable: growable);
deserialize(value, targetType, growable: growable);

@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use deserializeAsync() instead.')
dynamic deserialize(String json, String targetType, {bool growable = false,}) {
dynamic deserialize(String value, String targetType, {bool growable = false,}) {
// Remove all spaces. Necessary for regular expressions as well.
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments

// If the expected target type is String, nothing to do...
return targetType == 'String'
? json
: _deserialize(jsonDecode(json), targetType, growable: growable);
? value
: fromJson(json.decode(value), targetType, growable: growable);
}

// ignore: deprecated_member_use_from_same_package
Expand All @@ -164,7 +164,8 @@ class ApiClient {
@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.')
String serialize(Object? value) => value == null ? '' : json.encode(value);

static dynamic _deserialize(dynamic value, String targetType, {bool growable = false}) {
/// Returns a native instance of an OpenAPI class matching the [specified type][targetType].
static dynamic fromJson(dynamic value, String targetType, {bool growable = false,}) {
try {
switch (targetType) {
case 'String':
Expand Down Expand Up @@ -197,18 +198,18 @@ class ApiClient {
dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toList(growable: growable);
}
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toSet();
}
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(),
value.values.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)),
value.values.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,)),
);
}
}
Expand Down Expand Up @@ -237,6 +238,17 @@ class DeserializationMessage {
final bool growable;
}

/// Primarily intended for use in an isolate.
Future<dynamic> decodeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well.
final targetType = message.targetType.replaceAll(' ', '');

// If the expected target type is String, nothing to do...
return targetType == 'String'
? message.json
: json.decode(message.json);
}

/// Primarily intended for use in an isolate.
Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well.
Expand All @@ -245,8 +257,8 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// If the expected target type is String, nothing to do...
return targetType == 'String'
? message.json
: ApiClient._deserialize(
jsonDecode(message.json),
: ApiClient.fromJson(
json.decode(message.json),
targetType,
growable: message.growable,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
http: '>=0.13.0 <0.14.0'
intl: '^0.17.0'
intl: '^0.18.0'
meta: '^1.1.8'
dev_dependencies:
test: '>=1.16.0 <1.18.0'

Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ class ApiClient {
);
}

Future<dynamic> deserializeAsync(String json, String targetType, {bool growable = false,}) async =>
Future<dynamic> deserializeAsync(String value, String targetType, {bool growable = false,}) async =>
// ignore: deprecated_member_use_from_same_package
deserialize(json, targetType, growable: growable);
deserialize(value, targetType, growable: growable);

@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use deserializeAsync() instead.')
dynamic deserialize(String json, String targetType, {bool growable = false,}) {
dynamic deserialize(String value, String targetType, {bool growable = false,}) {
// Remove all spaces. Necessary for regular expressions as well.
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments

// If the expected target type is String, nothing to do...
return targetType == 'String'
? json
: _deserialize(jsonDecode(json), targetType, growable: growable);
? value
: fromJson(json.decode(value), targetType, growable: growable);
}

// ignore: deprecated_member_use_from_same_package
Expand All @@ -164,7 +164,8 @@ class ApiClient {
@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.')
String serialize(Object? value) => value == null ? '' : json.encode(value);

static dynamic _deserialize(dynamic value, String targetType, {bool growable = false}) {
/// Returns a native instance of an OpenAPI class matching the [specified type][targetType].
static dynamic fromJson(dynamic value, String targetType, {bool growable = false,}) {
try {
switch (targetType) {
case 'String':
Expand Down Expand Up @@ -281,18 +282,18 @@ class ApiClient {
dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toList(growable: growable);
}
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toSet();
}
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(),
value.values.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)),
value.values.map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,)),
);
}
}
Expand Down Expand Up @@ -321,6 +322,17 @@ class DeserializationMessage {
final bool growable;
}

/// Primarily intended for use in an isolate.
Future<dynamic> decodeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well.
final targetType = message.targetType.replaceAll(' ', '');

// If the expected target type is String, nothing to do...
return targetType == 'String'
? message.json
: json.decode(message.json);
}

/// Primarily intended for use in an isolate.
Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well.
Expand All @@ -329,8 +341,8 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// If the expected target type is String, nothing to do...
return targetType == 'String'
? message.json
: ApiClient._deserialize(
jsonDecode(message.json),
: ApiClient.fromJson(
json.decode(message.json),
targetType,
growable: message.growable,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
http: '>=0.13.0 <0.14.0'
intl: '^0.17.0'
intl: '^0.18.0'
meta: '^1.1.8'
dev_dependencies:
test: '>=1.16.0 <1.18.0'