Introduce changes necessary for Dart 3.0.0/Flutter 3.10.0 (#15516)

* Expose `deserialize` function.

* Rename `json` argument.

* Generate Petstore code.

* Upgrade minimum version of `intl` dependency.
This commit is contained in:
Noor Dawod 2023-06-20 03:35:25 +02:00 committed by GitHub
parent e0d89c3846
commit 3dd93beac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 37 deletions

View File

@ -134,19 +134,19 @@ class ApiClient {
} }
{{#native_serialization}} {{#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 // 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.') @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. // Remove all spaces. Necessary for regular expressions as well.
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments
// If the expected target type is String, nothing to do... // If the expected target type is String, nothing to do...
return targetType == 'String' return targetType == 'String'
? json ? value
: _deserialize(jsonDecode(json), targetType, growable: growable); : fromJson(json.decode(value), targetType, growable: growable);
} }
{{/native_serialization}} {{/native_serialization}}
@ -157,7 +157,8 @@ class ApiClient {
String serialize(Object? value) => value == null ? '' : json.encode(value); String serialize(Object? value) => value == null ? '' : json.encode(value);
{{#native_serialization}} {{#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 { try {
switch (targetType) { switch (targetType) {
case 'String': case 'String':
@ -189,18 +190,18 @@ class ApiClient {
dynamic match; dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) { if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)) .map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toList(growable: growable); .toList(growable: growable);
} }
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) { if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)) .map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toSet(); .toSet();
} }
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) { if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables( return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(), 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,)),
); );
} }
} }
@ -231,6 +232,17 @@ class DeserializationMessage {
final bool growable; 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. /// Primarily intended for use in an isolate.
Future<dynamic> deserializeAsync(DeserializationMessage message) async { Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well. // Remove all spaces. Necessary for regular expressions as well.
@ -239,8 +251,8 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// If the expected target type is String, nothing to do... // If the expected target type is String, nothing to do...
return targetType == 'String' return targetType == 'String'
? message.json ? message.json
: ApiClient._deserialize( : ApiClient.fromJson(
jsonDecode(message.json), json.decode(message.json),
targetType, targetType,
growable: message.growable, growable: message.growable,
); );

View File

@ -16,10 +16,10 @@ environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
http: '>=0.13.0 <0.14.0' http: '>=0.13.0 <0.14.0'
intl: '^0.17.0' intl: '^0.18.0'
meta: '^1.1.8' meta: '^1.1.8'
dev_dependencies: dev_dependencies:
test: '>=1.16.0 <1.18.0' test: '>=1.16.0 <1.18.0'
{{#json_serializable}} {{#json_serializable}}
build_runner: '^1.10.9' build_runner: '^1.10.9'
json_serializable: '^3.5.1'{{/json_serializable}} json_serializable: '^3.5.1'{{/json_serializable}}

View File

@ -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 // 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.') @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. // Remove all spaces. Necessary for regular expressions as well.
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments
// If the expected target type is String, nothing to do... // If the expected target type is String, nothing to do...
return targetType == 'String' return targetType == 'String'
? json ? value
: _deserialize(jsonDecode(json), targetType, growable: growable); : fromJson(json.decode(value), targetType, growable: growable);
} }
// ignore: deprecated_member_use_from_same_package // ignore: deprecated_member_use_from_same_package
@ -164,7 +164,8 @@ class ApiClient {
@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.') @Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.')
String serialize(Object? value) => value == null ? '' : json.encode(value); 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 { try {
switch (targetType) { switch (targetType) {
case 'String': case 'String':
@ -197,18 +198,18 @@ class ApiClient {
dynamic match; dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) { if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)) .map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toList(growable: growable); .toList(growable: growable);
} }
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) { if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)) .map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toSet(); .toSet();
} }
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) { if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables( return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(), 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,)),
); );
} }
} }
@ -237,6 +238,17 @@ class DeserializationMessage {
final bool growable; 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. /// Primarily intended for use in an isolate.
Future<dynamic> deserializeAsync(DeserializationMessage message) async { Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well. // Remove all spaces. Necessary for regular expressions as well.
@ -245,8 +257,8 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// If the expected target type is String, nothing to do... // If the expected target type is String, nothing to do...
return targetType == 'String' return targetType == 'String'
? message.json ? message.json
: ApiClient._deserialize( : ApiClient.fromJson(
jsonDecode(message.json), json.decode(message.json),
targetType, targetType,
growable: message.growable, growable: message.growable,
); );

View File

@ -10,7 +10,8 @@ environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
http: '>=0.13.0 <0.14.0' http: '>=0.13.0 <0.14.0'
intl: '^0.17.0' intl: '^0.18.0'
meta: '^1.1.8' meta: '^1.1.8'
dev_dependencies: dev_dependencies:
test: '>=1.16.0 <1.18.0' test: '>=1.16.0 <1.18.0'

View File

@ -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 // 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.') @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. // Remove all spaces. Necessary for regular expressions as well.
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments
// If the expected target type is String, nothing to do... // If the expected target type is String, nothing to do...
return targetType == 'String' return targetType == 'String'
? json ? value
: _deserialize(jsonDecode(json), targetType, growable: growable); : fromJson(json.decode(value), targetType, growable: growable);
} }
// ignore: deprecated_member_use_from_same_package // ignore: deprecated_member_use_from_same_package
@ -164,7 +164,8 @@ class ApiClient {
@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.') @Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.')
String serialize(Object? value) => value == null ? '' : json.encode(value); 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 { try {
switch (targetType) { switch (targetType) {
case 'String': case 'String':
@ -279,18 +280,18 @@ class ApiClient {
dynamic match; dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) { if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
return value return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)) .map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toList(growable: growable); .toList(growable: growable);
} }
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) { if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
return value return value
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)) .map<dynamic>((dynamic v) => fromJson(v, match, growable: growable,))
.toSet(); .toSet();
} }
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) { if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
return Map<String, dynamic>.fromIterables( return Map<String, dynamic>.fromIterables(
value.keys.cast<String>(), 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,)),
); );
} }
} }
@ -319,6 +320,17 @@ class DeserializationMessage {
final bool growable; 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. /// Primarily intended for use in an isolate.
Future<dynamic> deserializeAsync(DeserializationMessage message) async { Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// Remove all spaces. Necessary for regular expressions as well. // Remove all spaces. Necessary for regular expressions as well.
@ -327,8 +339,8 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async {
// If the expected target type is String, nothing to do... // If the expected target type is String, nothing to do...
return targetType == 'String' return targetType == 'String'
? message.json ? message.json
: ApiClient._deserialize( : ApiClient.fromJson(
jsonDecode(message.json), json.decode(message.json),
targetType, targetType,
growable: message.growable, growable: message.growable,
); );

View File

@ -10,7 +10,8 @@ environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
http: '>=0.13.0 <0.14.0' http: '>=0.13.0 <0.14.0'
intl: '^0.17.0' intl: '^0.18.0'
meta: '^1.1.8' meta: '^1.1.8'
dev_dependencies: dev_dependencies:
test: '>=1.16.0 <1.18.0' test: '>=1.16.0 <1.18.0'