diff --git a/modules/openapi-generator/src/main/resources/dart2/api_helper.mustache b/modules/openapi-generator/src/main/resources/dart2/api_helper.mustache index ec98b7d1d741..6268a5af3e48 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_helper.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_helper.mustache @@ -86,7 +86,7 @@ DateTime? mapDateTime(dynamic map, String key, [String? pattern]) { if (value is int) { millis = value; } else if (value is String) { - if (pattern == _dateEpochMarker) { + if (_isEpochMarker(pattern)) { millis = int.tryParse(value); } else { return DateTime.tryParse(value); diff --git a/modules/openapi-generator/src/main/resources/dart2/apilib.mustache b/modules/openapi-generator/src/main/resources/dart2/apilib.mustache index 2fcebda4ea46..876eba03cc6e 100644 --- a/modules/openapi-generator/src/main/resources/dart2/apilib.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/apilib.mustache @@ -31,3 +31,5 @@ final _regSet = RegExp(r'^Set<(.*)>$'); final _regMap = RegExp(r'^Map$'); ApiClient defaultApiClient = ApiClient(); + +bool _isEpochMarker(String? pattern) => pattern == _dateEpochMarker || pattern == '/$_dateEpochMarker/'; diff --git a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache index a8a6273cf280..6700c86ed1de 100644 --- a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache @@ -66,7 +66,7 @@ class {{{classname}}} { {{/isNullable}} {{#isDateTime}} {{#pattern}} - json[r'{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}' + json[r'{{{baseName}}}'] = _isEpochMarker(r'{{{pattern}}}') ? this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.millisecondsSinceEpoch : this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.toUtc().toIso8601String(); {{/pattern}} @@ -76,7 +76,7 @@ class {{{classname}}} { {{/isDateTime}} {{#isDate}} {{#pattern}} - json[r'{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}' + json[r'{{{baseName}}}'] = _isEpochMarker(r'{{{pattern}}}') ? this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.millisecondsSinceEpoch : _dateFormatter.format(this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.toUtc()); {{/pattern}} @@ -128,10 +128,10 @@ class {{{classname}}} { return {{{classname}}}( {{#vars}} {{#isDateTime}} - {{{name}}}: mapDateTime(json, r'{{{baseName}}}', '{{{pattern}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, + {{{name}}}: mapDateTime(json, r'{{{baseName}}}', r'{{{pattern}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, {{/isDateTime}} {{#isDate}} - {{{name}}}: mapDateTime(json, r'{{{baseName}}}', '{{{pattern}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, + {{{name}}}: mapDateTime(json, r'{{{baseName}}}', r'{{{pattern}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, {{/isDate}} {{^isDateTime}} {{^isDate}} @@ -211,9 +211,9 @@ class {{{classname}}} { {{/isMap}} {{^isMap}} {{#isNumber}} - {{{name}}}: json[r'{{{baseName}}}'] == null + {{{name}}}: {{#isNullable}}json[r'{{{baseName}}}'] == null ? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}} - : {{{datatypeWithEnum}}}.parse(json[r'{{{baseName}}}'].toString()), + : {{/isNullable}}{{{datatypeWithEnum}}}.parse('${json[r'{{{baseName}}}']}'), {{/isNumber}} {{^isNumber}} {{^isEnum}} diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api.dart index 742bcfa11543..e7da4386a7dd 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api.dart @@ -47,3 +47,5 @@ final _regSet = RegExp(r'^Set<(.*)>$'); final _regMap = RegExp(r'^Map$'); ApiClient defaultApiClient = ApiClient(); + +bool _isEpochMarker(String? pattern) => pattern == _dateEpochMarker || pattern == '/$_dateEpochMarker/'; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_helper.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_helper.dart index d6adb1798250..b0d63582d2f0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_helper.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_helper.dart @@ -87,7 +87,7 @@ DateTime? mapDateTime(dynamic map, String key, [String? pattern]) { if (value is int) { millis = value; } else if (value is String) { - if (pattern == _dateEpochMarker) { + if (_isEpochMarker(pattern)) { millis = int.tryParse(value); } else { return DateTime.tryParse(value); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart index 0894d4b295c5..e052dcc544a9 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart @@ -133,7 +133,7 @@ class Order { id: mapValueOfType(json, r'id'), petId: mapValueOfType(json, r'petId'), quantity: mapValueOfType(json, r'quantity'), - shipDate: mapDateTime(json, r'shipDate', ''), + shipDate: mapDateTime(json, r'shipDate', r''), status: OrderStatusEnum.fromJson(json[r'status']), complete: mapValueOfType(json, r'complete') ?? false, ); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart index 78bbb5b3f0de..3354e842e543 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart @@ -92,3 +92,5 @@ final _regSet = RegExp(r'^Set<(.*)>$'); final _regMap = RegExp(r'^Map$'); ApiClient defaultApiClient = ApiClient(); + +bool _isEpochMarker(String? pattern) => pattern == _dateEpochMarker || pattern == '/$_dateEpochMarker/'; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_helper.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_helper.dart index 4a29277289d8..77898c911eee 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_helper.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_helper.dart @@ -105,7 +105,7 @@ DateTime? mapDateTime(dynamic map, String key, [String? pattern]) { if (value is int) { millis = value; } else if (value is String) { - if (pattern == _dateEpochMarker) { + if (_isEpochMarker(pattern)) { millis = int.tryParse(value); } else { return DateTime.tryParse(value); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/fake_big_decimal_map200_response.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/fake_big_decimal_map200_response.dart index bb878b52c06e..eae75fa0fa26 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/fake_big_decimal_map200_response.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/fake_big_decimal_map200_response.dart @@ -71,9 +71,7 @@ class FakeBigDecimalMap200Response { }()); return FakeBigDecimalMap200Response( - someId: json[r'someId'] == null - ? null - : num.parse(json[r'someId'].toString()), + someId: num.parse('${json[r'someId']}'), someMap: mapCastOfType(json, r'someMap') ?? const {}, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/format_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/format_test.dart index 9bacccfef3d7..67d169c4d8a2 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/format_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/format_test.dart @@ -280,17 +280,15 @@ class FormatTest { integer: mapValueOfType(json, r'integer'), int32: mapValueOfType(json, r'int32'), int64: mapValueOfType(json, r'int64'), - number: json[r'number'] == null - ? null - : num.parse(json[r'number'].toString()), + number: num.parse('${json[r'number']}'), float: mapValueOfType(json, r'float'), double_: mapValueOfType(json, r'double'), decimal: mapValueOfType(json, r'decimal'), string: mapValueOfType(json, r'string'), byte: mapValueOfType(json, r'byte')!, binary: null, // No support for decoding binary content from JSON - date: mapDateTime(json, r'date', '')!, - dateTime: mapDateTime(json, r'dateTime', ''), + date: mapDateTime(json, r'date', r'')!, + dateTime: mapDateTime(json, r'dateTime', r''), uuid: mapValueOfType(json, r'uuid'), password: mapValueOfType(json, r'password')!, patternWithDigits: mapValueOfType(json, r'pattern_with_digits'), diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart index dfca68e14dce..976cbee2afea 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/mixed_properties_and_additional_properties_class.dart @@ -88,7 +88,7 @@ class MixedPropertiesAndAdditionalPropertiesClass { return MixedPropertiesAndAdditionalPropertiesClass( uuid: mapValueOfType(json, r'uuid'), - dateTime: mapDateTime(json, r'dateTime', ''), + dateTime: mapDateTime(json, r'dateTime', r''), map: Animal.mapFromJson(json[r'map']), ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart index 0a5a70afa506..ed9b75289ff2 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/nullable_class.dart @@ -164,11 +164,11 @@ class NullableClass { integerProp: mapValueOfType(json, r'integer_prop'), numberProp: json[r'number_prop'] == null ? null - : num.parse(json[r'number_prop'].toString()), + : num.parse('${json[r'number_prop']}'), booleanProp: mapValueOfType(json, r'boolean_prop'), stringProp: mapValueOfType(json, r'string_prop'), - dateProp: mapDateTime(json, r'date_prop', ''), - datetimeProp: mapDateTime(json, r'datetime_prop', ''), + dateProp: mapDateTime(json, r'date_prop', r''), + datetimeProp: mapDateTime(json, r'datetime_prop', r''), arrayNullableProp: Object.listFromJson(json[r'array_nullable_prop']), arrayAndItemsNullableProp: Object.listFromJson(json[r'array_and_items_nullable_prop']), arrayItemsNullable: Object.listFromJson(json[r'array_items_nullable']), diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/number_only.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/number_only.dart index 405f9f326b8b..74366c354254 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/number_only.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/number_only.dart @@ -65,9 +65,7 @@ class NumberOnly { }()); return NumberOnly( - justNumber: json[r'JustNumber'] == null - ? null - : num.parse(json[r'JustNumber'].toString()), + justNumber: num.parse('${json[r'JustNumber']}'), ); } return null; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart index 91932b3bc411..2afb378ba25b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_deprecated_fields.dart @@ -104,9 +104,7 @@ class ObjectWithDeprecatedFields { return ObjectWithDeprecatedFields( uuid: mapValueOfType(json, r'uuid'), - id: json[r'id'] == null - ? null - : num.parse(json[r'id'].toString()), + id: num.parse('${json[r'id']}'), deprecatedRef: DeprecatedObject.fromJson(json[r'deprecatedRef']), bars: json[r'bars'] is Iterable ? (json[r'bars'] as Iterable).cast().toList(growable: false) diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart index 0894d4b295c5..e052dcc544a9 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart @@ -133,7 +133,7 @@ class Order { id: mapValueOfType(json, r'id'), petId: mapValueOfType(json, r'petId'), quantity: mapValueOfType(json, r'quantity'), - shipDate: mapDateTime(json, r'shipDate', ''), + shipDate: mapDateTime(json, r'shipDate', r''), status: OrderStatusEnum.fromJson(json[r'status']), complete: mapValueOfType(json, r'complete') ?? false, ); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_composite.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_composite.dart index f0e549abf66a..2acc8f718dbb 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_composite.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_composite.dart @@ -97,9 +97,7 @@ class OuterComposite { }()); return OuterComposite( - myNumber: json[r'my_number'] == null - ? null - : num.parse(json[r'my_number'].toString()), + myNumber: num.parse('${json[r'my_number']}'), myString: mapValueOfType(json, r'my_string'), myBoolean: mapValueOfType(json, r'my_boolean'), );