From 5b44aaf8d7fe6aa376661e80422d9ee3db2b70b6 Mon Sep 17 00:00:00 2001 From: Antonio Sagliocco Date: Sat, 4 Jun 2022 15:59:46 +0200 Subject: [PATCH] [Dart][Client] Support parsing DateTime (#12433) * Support DateTime parsing I've got issue in parsing an Array of Strings in datetime format, which the generator translates into a List. This just fixes it * update dart sampels Co-authored-by: William Cheng --- .../src/main/resources/dart2/api_client.mustache | 2 ++ .../petstore/dart2/petstore_client_lib/lib/api_client.dart | 2 ++ .../petstore/dart2/petstore_client_lib_fake/lib/api_client.dart | 2 ++ 3 files changed, 6 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache index 8eae959e3e5..d8db09013b9 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache @@ -183,6 +183,8 @@ class ApiClient { } final valueString = '$value'.toLowerCase(); return valueString == 'true' || valueString == '1'; + case 'DateTime': + return value is DateTime ? value : DateTime.tryParse(value); {{#models}} {{#model}} case '{{{classname}}}': diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart index 79977d854b6..ce5560f03f0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart @@ -190,6 +190,8 @@ class ApiClient { } final valueString = '$value'.toLowerCase(); return valueString == 'true' || valueString == '1'; + case 'DateTime': + return value is DateTime ? value : DateTime.tryParse(value); case 'ApiResponse': return ApiResponse.fromJson(value); case 'Category': diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart index 65fc8807797..94a25909e6d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart @@ -190,6 +190,8 @@ class ApiClient { } final valueString = '$value'.toLowerCase(); return valueString == 'true' || valueString == '1'; + case 'DateTime': + return value is DateTime ? value : DateTime.tryParse(value); case 'AdditionalPropertiesClass': return AdditionalPropertiesClass.fromJson(value); case 'AllOfWithSingleRef':