From 4c62b345815890d96cbc769fc9f41d95da83035a Mon Sep 17 00:00:00 2001 From: agilob Date: Wed, 3 Mar 2021 20:21:59 +0000 Subject: [PATCH 1/9] Fix api-client deserialization for json_serializable --- .../src/main/resources/dart2/api.mustache | 32 ++-- .../main/resources/dart2/api_client.mustache | 24 +-- .../main/resources/dart2/api_helper.mustache | 3 +- .../lib/api/another_fake_api.dart | 6 +- .../lib/api/default_api.dart | 6 +- .../lib/api/fake_api.dart | 54 +++---- .../lib/api/fake_classname_tags123_api.dart | 6 +- .../lib/api/pet_api.dart | 44 +++--- .../lib/api/store_api.dart | 20 +-- .../lib/api/user_api.dart | 24 +-- .../lib/api_client.dart | 148 +----------------- .../lib/api_helper.dart | 15 +- 12 files changed, 117 insertions(+), 265 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index ad30ec2cdf03..af852b117566 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -61,7 +61,7 @@ class {{{classname}}} { {{/allParams}} {{/hasParams}} - final path = '{{{path}}}'{{#pathParams}} + final path = r'{{{path}}}'{{#pathParams}} .replaceAll('{' + '{{{baseName}}}' + '}', {{{paramName}}}.toString()){{/pathParams}}; Object postBody{{#bodyParam}} = {{{paramName}}}{{/bodyParam}}; @@ -185,21 +185,23 @@ class {{{classname}}} { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - {{#isArray}} - return (apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as List) - .cast<{{{returnBaseType}}}>() - .{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}}; - {{/isArray}} - {{^isArray}} - {{#isMap}} - return {{{returnType}}}.from(apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}')); - {{/isMap}} - {{^isMap}} - return apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as {{{returnType}}}; - {{/isMap}} - {{/isArray}} + {{#isArray}} + final l = json.decode(response.body); + return {{{returnType}}}.from(l.map((model) => Pet.fromJson(model))); + {{/isArray}} + {{^isArray}} + {{#isMap}} + return {{{returnType}}}.from(json.decode(response.body)); + {{/isMap}} + {{^isMap}} + return {{{returnType}}}.fromJson(json.decode(response.body)); + {{/isMap}} + {{/isArray}} + {{#isString}} + return json.decode(response.body); + {{/isString}} } - return null; + return Future.value(null); {{/returnType}} } {{/operation}} 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 e231ff72859d..a5d3b0948e7c 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache @@ -56,17 +56,6 @@ class ApiClient { Map get authentications => Map.unmodifiable(_authentications); - dynamic deserialize(String json, String targetType, {bool growable}) { - // Remove all spaces. Necessary for reg expressions as well. - targetType = targetType.replaceAll(' ', ''); - - return targetType == 'String' - ? json - : _deserialize(jsonDecode(json), targetType, growable: true == growable); - } - - String serialize(Object obj) => obj == null ? '' : json.encode(obj); - T getAuthentication(String name) { final authentication = _authentications[name]; return authentication is T ? authentication : null; @@ -159,6 +148,7 @@ class ApiClient { throw ApiException(HttpStatus.badRequest, 'Invalid HTTP operation: $method $path',); } +{{#native_serialization}} dynamic _deserialize(dynamic value, String targetType, {bool growable}) { try { switch (targetType) { @@ -216,6 +206,18 @@ class ApiClient { throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',); } + dynamic deserialize(String json, String targetType, {bool growable}) { + // Remove all spaces. Necessary for reg expressions as well. + targetType = targetType.replaceAll(' ', ''); + + return targetType == 'String' + ? json + : _deserialize(jsonDecode(json), targetType, growable: true == growable); + } +{{/native_serialization}} + + String serialize(Object obj) => obj == null ? '' : json.encode(obj); + /// Update query and header parameters based on authentication settings. /// @param authNames The authentications to apply void _updateParamsForAuth( 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 823829acd9c8..8e70b9920bfb 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_helper.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_helper.mustache @@ -53,8 +53,7 @@ String parameterToString(dynamic value) { {{#model}} {{#isEnum}} if (value is {{{classname}}}) { -{{#native_serialization}} return {{{classname}}}TypeTransformer().encode(value).toString();{{/native_serialization}} -{{#json_serializable}} return _${{{classname}}}EnumMap[value];{{/json_serializable}} +{{#native_serialization}} return {{{classname}}}TypeTransformer().encode(value).toString();{{/native_serialization}}{{#json_serializable}} return value.toString();{{/json_serializable}} } {{/isEnum}} {{/model}} diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart index cdf8eb623c9b..7aae686d77b6 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart @@ -31,7 +31,7 @@ class AnotherFakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/another-fake/dummy'; + final path = r'/another-fake/dummy'; Object postBody = modelClient; @@ -84,8 +84,8 @@ class AnotherFakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; + return ModelClient.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart index 24fba9d8349e..0a00c3eca905 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart @@ -17,7 +17,7 @@ class DefaultApi { /// Performs an HTTP 'GET /foo' operation and returns the [Response]. Future fooGetWithHttpInfo() async { - final path = '/foo'; + final path = r'/foo'; Object postBody; @@ -62,8 +62,8 @@ class DefaultApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'InlineResponseDefault') as InlineResponseDefault; + return InlineResponseDefault.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart index e81da089940d..e3f158d136c5 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart @@ -19,7 +19,7 @@ class FakeApi { /// /// Note: This method returns the HTTP [Response]. Future fakeHealthGetWithHttpInfo() async { - final path = '/fake/health'; + final path = r'/fake/health'; Object postBody; @@ -65,9 +65,9 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'HealthCheckResult') as HealthCheckResult; + return HealthCheckResult.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// test http signature authentication @@ -90,7 +90,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/fake/http-signature-test'; + final path = r'/fake/http-signature-test'; Object postBody = pet; @@ -164,7 +164,7 @@ class FakeApi { Future fakeOuterBooleanSerializeWithHttpInfo({ bool body }) async { // Verify required params are set. - final path = '/fake/outer/boolean'; + final path = r'/fake/outer/boolean'; Object postBody = body; @@ -215,9 +215,9 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'bool') as bool; + return bool.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Test serialization of object with outer number type @@ -231,7 +231,7 @@ class FakeApi { Future fakeOuterCompositeSerializeWithHttpInfo({ OuterComposite outerComposite }) async { // Verify required params are set. - final path = '/fake/outer/composite'; + final path = r'/fake/outer/composite'; Object postBody = outerComposite; @@ -282,9 +282,9 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'OuterComposite') as OuterComposite; + return OuterComposite.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Test serialization of outer number types @@ -298,7 +298,7 @@ class FakeApi { Future fakeOuterNumberSerializeWithHttpInfo({ num body }) async { // Verify required params are set. - final path = '/fake/outer/number'; + final path = r'/fake/outer/number'; Object postBody = body; @@ -349,9 +349,9 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'num') as num; + return num.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Test serialization of outer string types @@ -365,7 +365,7 @@ class FakeApi { Future fakeOuterStringSerializeWithHttpInfo({ String body }) async { // Verify required params are set. - final path = '/fake/outer/string'; + final path = r'/fake/outer/string'; Object postBody = body; @@ -416,9 +416,9 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + return String.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// For this test, the body for this request much reference a schema named `File`. @@ -434,7 +434,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: fileSchemaTestClass'); } - final path = '/fake/body-with-file-schema'; + final path = r'/fake/body-with-file-schema'; Object postBody = fileSchemaTestClass; @@ -497,7 +497,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/fake/body-with-query-params'; + final path = r'/fake/body-with-query-params'; Object postBody = user; @@ -563,7 +563,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/fake'; + final path = r'/fake'; Object postBody = modelClient; @@ -616,9 +616,9 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; + return ModelClient.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -685,7 +685,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: byte'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -905,7 +905,7 @@ class FakeApi { Future testEnumParametersWithHttpInfo({ List enumHeaderStringArray, String enumHeaderString, List enumQueryStringArray, String enumQueryString, int enumQueryInteger, double enumQueryDouble, List enumFormStringArray, String enumFormString }) async { // Verify required params are set. - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -1048,7 +1048,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requiredInt64Group'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -1142,7 +1142,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requestBody'); } - final path = '/fake/inline-additionalProperties'; + final path = r'/fake/inline-additionalProperties'; Object postBody = requestBody; @@ -1211,7 +1211,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: param2'); } - final path = '/fake/jsonFormData'; + final path = r'/fake/jsonFormData'; Object postBody; @@ -1310,7 +1310,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: context'); } - final path = '/fake/test-query-paramters'; + final path = r'/fake/test-query-paramters'; Object postBody; diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart index 66a5c292f0c6..51ed8e1e8828 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart @@ -31,7 +31,7 @@ class FakeClassnameTags123Api { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/fake_classname_test'; + final path = r'/fake_classname_test'; Object postBody = modelClient; @@ -84,8 +84,8 @@ class FakeClassnameTags123Api { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; + return ModelClient.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart index 71abeecfdd9c..505856c803e8 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart @@ -29,7 +29,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -94,7 +94,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -166,7 +166,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: status'); } - final path = '/pet/findByStatus'; + final path = r'/pet/findByStatus'; Object postBody; @@ -221,11 +221,10 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() - .toList(growable: false); + final l = json.decode(response.body); + return List.from(l.map((model) => Pet.fromJson(model))); } - return null; + return Future.value(null); } /// Finds Pets by tags @@ -244,7 +243,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -299,11 +298,10 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'Set') as List) - .cast() - .toSet(); + final l = json.decode(response.body); + return Set.from(l.map((model) => Pet.fromJson(model))); } - return null; + return Future.value(null); } /// Find pet by ID @@ -322,7 +320,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -376,9 +374,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; + return Pet.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Update an existing pet @@ -395,7 +393,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -464,7 +462,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -554,7 +552,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}/uploadImage' + final path = r'/pet/{petId}/uploadImage' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -624,9 +622,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; + return ApiResponse.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// uploads an image (required) @@ -652,7 +650,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requiredFile'); } - final path = '/fake/{petId}/uploadImageWithRequiredFile' + final path = r'/fake/{petId}/uploadImageWithRequiredFile' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -722,8 +720,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; + return ApiResponse.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart index bf83f6a25231..289f48d2abe0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart @@ -31,7 +31,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{order_id}' + final path = r'/store/order/{order_id}' .replaceAll('{' + 'order_id' + '}', orderId.toString()); Object postBody; @@ -89,7 +89,7 @@ class StoreApi { /// /// Note: This method returns the HTTP [Response]. Future getInventoryWithHttpInfo() async { - final path = '/store/inventory'; + final path = r'/store/inventory'; Object postBody; @@ -137,9 +137,9 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); + return Map.from(json.decode(response.body)); } - return null; + return Future.value(null); } /// Find purchase order by ID @@ -158,7 +158,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{order_id}' + final path = r'/store/order/{order_id}' .replaceAll('{' + 'order_id' + '}', orderId.toString()); Object postBody; @@ -212,9 +212,9 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Place an order for a pet @@ -231,7 +231,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: order'); } - final path = '/store/order'; + final path = r'/store/order'; Object postBody = order; @@ -282,8 +282,8 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart index 76d477efeb36..e1981eeb471c 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart @@ -31,7 +31,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user'; + final path = r'/user'; Object postBody = user; @@ -96,7 +96,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/createWithArray'; + final path = r'/user/createWithArray'; Object postBody = user; @@ -159,7 +159,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/createWithList'; + final path = r'/user/createWithList'; Object postBody = user; @@ -224,7 +224,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -290,7 +290,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -342,9 +342,9 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; + return User.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Logs user into the system @@ -367,7 +367,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: password'); } - final path = '/user/login'; + final path = r'/user/login'; Object postBody; @@ -424,16 +424,16 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + return String.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Logs out current logged in user session /// /// Note: This method returns the HTTP [Response]. Future logoutUserWithHttpInfo() async { - final path = '/user/logout'; + final path = r'/user/logout'; Object postBody; @@ -499,7 +499,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody = user; diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_client.dart index 435fdfc4b74a..593d552210b5 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_client.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_client.dart @@ -52,17 +52,6 @@ class ApiClient { Map get authentications => Map.unmodifiable(_authentications); - dynamic deserialize(String json, String targetType, {bool growable}) { - // Remove all spaces. Necessary for reg expressions as well. - targetType = targetType.replaceAll(' ', ''); - - return targetType == 'String' - ? json - : _deserialize(jsonDecode(json), targetType, growable: true == growable); - } - - String serialize(Object obj) => obj == null ? '' : json.encode(obj); - T getAuthentication(String name) { final authentication = _authentications[name]; return authentication is T ? authentication : null; @@ -155,141 +144,8 @@ class ApiClient { throw ApiException(HttpStatus.badRequest, 'Invalid HTTP operation: $method $path',); } - dynamic _deserialize(dynamic value, String targetType, {bool growable}) { - try { - switch (targetType) { - case 'String': - return '$value'; - case 'int': - return value is int ? value : int.parse('$value'); - case 'bool': - if (value is bool) { - return value; - } - final valueString = '$value'.toLowerCase(); - return valueString == 'true' || valueString == '1'; - break; - case 'double': - return value is double ? value : double.parse('$value'); - case 'AdditionalPropertiesClass': - return AdditionalPropertiesClass.fromJson(value); - case 'Animal': - return Animal.fromJson(value); - case 'ApiResponse': - return ApiResponse.fromJson(value); - case 'ArrayOfArrayOfNumberOnly': - return ArrayOfArrayOfNumberOnly.fromJson(value); - case 'ArrayOfNumberOnly': - return ArrayOfNumberOnly.fromJson(value); - case 'ArrayTest': - return ArrayTest.fromJson(value); - case 'Capitalization': - return Capitalization.fromJson(value); - case 'Cat': - return Cat.fromJson(value); - case 'CatAllOf': - return CatAllOf.fromJson(value); - case 'Category': - return Category.fromJson(value); - case 'ClassModel': - return ClassModel.fromJson(value); - case 'Dog': - return Dog.fromJson(value); - case 'DogAllOf': - return DogAllOf.fromJson(value); - case 'EnumArrays': - return EnumArrays.fromJson(value); - case 'EnumClass': - - return _$enumDecode(_$EnumClassEnumMap, value); - case 'EnumTest': - return EnumTest.fromJson(value); - case 'FileSchemaTestClass': - return FileSchemaTestClass.fromJson(value); - case 'Foo': - return Foo.fromJson(value); - case 'FormatTest': - return FormatTest.fromJson(value); - case 'HasOnlyReadOnly': - return HasOnlyReadOnly.fromJson(value); - case 'HealthCheckResult': - return HealthCheckResult.fromJson(value); - case 'InlineResponseDefault': - return InlineResponseDefault.fromJson(value); - case 'MapTest': - return MapTest.fromJson(value); - case 'MixedPropertiesAndAdditionalPropertiesClass': - return MixedPropertiesAndAdditionalPropertiesClass.fromJson(value); - case 'Model200Response': - return Model200Response.fromJson(value); - case 'ModelClient': - return ModelClient.fromJson(value); - case 'ModelFile': - return ModelFile.fromJson(value); - case 'ModelList': - return ModelList.fromJson(value); - case 'ModelReturn': - return ModelReturn.fromJson(value); - case 'Name': - return Name.fromJson(value); - case 'NullableClass': - return NullableClass.fromJson(value); - case 'NumberOnly': - return NumberOnly.fromJson(value); - case 'Order': - return Order.fromJson(value); - case 'OuterComposite': - return OuterComposite.fromJson(value); - case 'OuterEnum': - - return _$enumDecode(_$OuterEnumEnumMap, value); - case 'OuterEnumDefaultValue': - - return _$enumDecode(_$OuterEnumDefaultValueEnumMap, value); - case 'OuterEnumInteger': - - return _$enumDecode(_$OuterEnumIntegerEnumMap, value); - case 'OuterEnumIntegerDefaultValue': - - return _$enumDecode(_$OuterEnumIntegerDefaultValueEnumMap, value); - case 'Pet': - return Pet.fromJson(value); - case 'ReadOnlyFirst': - return ReadOnlyFirst.fromJson(value); - case 'SpecialModelName': - return SpecialModelName.fromJson(value); - case 'Tag': - return Tag.fromJson(value); - case 'User': - return User.fromJson(value); - default: - Match match; - if (value is List && (match = _regList.firstMatch(targetType)) != null) { - final newTargetType = match[1]; - return value - .map((v) => _deserialize(v, newTargetType, growable: growable)) - .toList(growable: true == growable); - } - if (value is Set && (match = _regSet.firstMatch(targetType)) != null) { - final newTargetType = match[1]; - return value - .map((v) => _deserialize(v, newTargetType, growable: growable)) - .toSet(); - } - if (value is Map && (match = _regMap.firstMatch(targetType)) != null) { - final newTargetType = match[1]; - return Map.fromIterables( - value.keys, - value.values.map((v) => _deserialize(v, newTargetType, growable: growable)), - ); - } - break; - } - } on Exception catch (e, stack) { - throw ApiException.withInner(HttpStatus.internalServerError, 'Exception during deserialization.', e, stack,); - } - throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',); - } + + String serialize(Object obj) => obj == null ? '' : json.encode(obj); /// Update query and header parameters based on authentication settings. /// @param authNames The authentications to apply diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_helper.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_helper.dart index 8e083e63f0a4..f9904f5ec71e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_helper.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api_helper.dart @@ -59,24 +59,19 @@ String parameterToString(dynamic value) { return value.toUtc().toIso8601String(); } if (value is EnumClass) { - - return _$EnumClassEnumMap[value]; + return value.toString(); } if (value is OuterEnum) { - - return _$OuterEnumEnumMap[value]; + return value.toString(); } if (value is OuterEnumDefaultValue) { - - return _$OuterEnumDefaultValueEnumMap[value]; + return value.toString(); } if (value is OuterEnumInteger) { - - return _$OuterEnumIntegerEnumMap[value]; + return value.toString(); } if (value is OuterEnumIntegerDefaultValue) { - - return _$OuterEnumIntegerDefaultValueEnumMap[value]; + return value.toString(); } return value.toString(); } From 7073f54be57d6b6b19f3935ab9fcc8e6f479c624 Mon Sep 17 00:00:00 2001 From: agilob Date: Wed, 3 Mar 2021 20:27:08 +0000 Subject: [PATCH 2/9] Use raw string for url path --- .../src/main/resources/dart2/api.mustache | 5 +-- .../petstore_client_lib/lib/api/pet_api.dart | 30 +++++++------ .../lib/api/store_api.dart | 14 +++---- .../petstore_client_lib/lib/api/user_api.dart | 20 ++++----- .../petstore_client_lib/lib/api_client.dart | 22 +++++----- .../petstore_client_lib/lib/api/pet_api.dart | 34 +++++++-------- .../lib/api/store_api.dart | 14 +++---- .../petstore_client_lib/lib/api/user_api.dart | 20 ++++----- .../petstore_client_lib/lib/api_client.dart | 22 +++++----- .../lib/api/another_fake_api.dart | 4 +- .../lib/api/default_api.dart | 4 +- .../lib/api/fake_api.dart | 42 +++++++++---------- .../lib/api/fake_classname_tags123_api.dart | 4 +- .../lib/api/pet_api.dart | 34 +++++++-------- .../lib/api/store_api.dart | 14 +++---- .../lib/api/user_api.dart | 20 ++++----- .../lib/api_client.dart | 22 +++++----- .../lib/api_helper.dart | 5 --- .../lib/api/another_fake_api.dart | 2 +- .../lib/api/default_api.dart | 2 +- .../lib/api/fake_api.dart | 12 +++--- .../lib/api/fake_classname_tags123_api.dart | 2 +- .../lib/api/pet_api.dart | 10 ++--- .../lib/api/store_api.dart | 6 +-- .../lib/api/user_api.dart | 4 +- 25 files changed, 177 insertions(+), 191 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index af852b117566..4b126db8500b 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -197,11 +197,8 @@ class {{{classname}}} { return {{{returnType}}}.fromJson(json.decode(response.body)); {{/isMap}} {{/isArray}} - {{#isString}} - return json.decode(response.body); - {{/isString}} } - return Future.value(null); + return null; {{/returnType}} } {{/operation}} diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index df7ee07412ed..d6b86a23b3ef 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -29,7 +29,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = body; @@ -94,7 +94,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -166,7 +166,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: status'); } - final path = '/pet/findByStatus'; + final path = r'/pet/findByStatus'; Object postBody; @@ -221,9 +221,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() - .toList(growable: false); + final l = json.decode(response.body); + return List.from(l.map((model) => Pet.fromJson(model))); } return null; } @@ -244,7 +243,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -299,9 +298,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() - .toList(growable: false); + final l = json.decode(response.body); + return List.from(l.map((model) => Pet.fromJson(model))); } return null; } @@ -322,7 +320,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -376,7 +374,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; + return Pet.fromJson(json.decode(response.body)); } return null; } @@ -395,7 +393,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = body; @@ -464,7 +462,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -554,7 +552,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}/uploadImage' + final path = r'/pet/{petId}/uploadImage' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -624,7 +622,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; + return ApiResponse.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart index 1f20bf42f74b..80a1d0ff30ce 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart @@ -31,7 +31,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{orderId}' + final path = r'/store/order/{orderId}' .replaceAll('{' + 'orderId' + '}', orderId.toString()); Object postBody; @@ -89,7 +89,7 @@ class StoreApi { /// /// Note: This method returns the HTTP [Response]. Future getInventoryWithHttpInfo() async { - final path = '/store/inventory'; + final path = r'/store/inventory'; Object postBody; @@ -137,7 +137,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); + return Map.from(json.decode(response.body)); } return null; } @@ -158,7 +158,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{orderId}' + final path = r'/store/order/{orderId}' .replaceAll('{' + 'orderId' + '}', orderId.toString()); Object postBody; @@ -212,7 +212,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } return null; } @@ -231,7 +231,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/store/order'; + final path = r'/store/order'; Object postBody = body; @@ -282,7 +282,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index a8a566239ca7..d3b3e7106469 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -31,7 +31,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/user'; + final path = r'/user'; Object postBody = body; @@ -96,7 +96,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/user/createWithArray'; + final path = r'/user/createWithArray'; Object postBody = body; @@ -159,7 +159,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/user/createWithList'; + final path = r'/user/createWithList'; Object postBody = body; @@ -224,7 +224,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -290,7 +290,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -342,7 +342,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; + return User.fromJson(json.decode(response.body)); } return null; } @@ -367,7 +367,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: password'); } - final path = '/user/login'; + final path = r'/user/login'; Object postBody; @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + return String.fromJson(json.decode(response.body)); } return null; } @@ -433,7 +433,7 @@ class UserApi { /// /// Note: This method returns the HTTP [Response]. Future logoutUserWithHttpInfo() async { - final path = '/user/logout'; + final path = r'/user/logout'; Object postBody; @@ -499,7 +499,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody = body; diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api_client.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api_client.dart index 9f875dba12d6..87a7a36d470b 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api_client.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api_client.dart @@ -49,17 +49,6 @@ class ApiClient { Map get authentications => Map.unmodifiable(_authentications); - dynamic deserialize(String json, String targetType, {bool growable}) { - // Remove all spaces. Necessary for reg expressions as well. - targetType = targetType.replaceAll(' ', ''); - - return targetType == 'String' - ? json - : _deserialize(jsonDecode(json), targetType, growable: true == growable); - } - - String serialize(Object obj) => obj == null ? '' : json.encode(obj); - T getAuthentication(String name) { final authentication = _authentications[name]; return authentication is T ? authentication : null; @@ -209,6 +198,17 @@ class ApiClient { throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',); } + dynamic deserialize(String json, String targetType, {bool growable}) { + // Remove all spaces. Necessary for reg expressions as well. + targetType = targetType.replaceAll(' ', ''); + + return targetType == 'String' + ? json + : _deserialize(jsonDecode(json), targetType, growable: true == growable); + } + + String serialize(Object obj) => obj == null ? '' : json.encode(obj); + /// Update query and header parameters based on authentication settings. /// @param authNames The authentications to apply void _updateParamsForAuth( diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index f0d8178af255..22e121c8ce21 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -29,7 +29,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -80,7 +80,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; + return Pet.fromJson(json.decode(response.body)); } return null; } @@ -101,7 +101,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -173,7 +173,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: status'); } - final path = '/pet/findByStatus'; + final path = r'/pet/findByStatus'; Object postBody; @@ -228,9 +228,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() - .toList(growable: false); + final l = json.decode(response.body); + return List.from(l.map((model) => Pet.fromJson(model))); } return null; } @@ -251,7 +250,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -306,9 +305,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() - .toList(growable: false); + final l = json.decode(response.body); + return List.from(l.map((model) => Pet.fromJson(model))); } return null; } @@ -329,7 +327,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -383,7 +381,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; + return Pet.fromJson(json.decode(response.body)); } return null; } @@ -402,7 +400,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -453,7 +451,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; + return Pet.fromJson(json.decode(response.body)); } return null; } @@ -478,7 +476,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -568,7 +566,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}/uploadImage' + final path = r'/pet/{petId}/uploadImage' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -638,7 +636,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; + return ApiResponse.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart index 121395c60f04..65417433adad 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart @@ -31,7 +31,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{orderId}' + final path = r'/store/order/{orderId}' .replaceAll('{' + 'orderId' + '}', orderId.toString()); Object postBody; @@ -89,7 +89,7 @@ class StoreApi { /// /// Note: This method returns the HTTP [Response]. Future getInventoryWithHttpInfo() async { - final path = '/store/inventory'; + final path = r'/store/inventory'; Object postBody; @@ -137,7 +137,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); + return Map.from(json.decode(response.body)); } return null; } @@ -158,7 +158,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{orderId}' + final path = r'/store/order/{orderId}' .replaceAll('{' + 'orderId' + '}', orderId.toString()); Object postBody; @@ -212,7 +212,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } return null; } @@ -231,7 +231,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: order'); } - final path = '/store/order'; + final path = r'/store/order'; Object postBody = order; @@ -282,7 +282,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index 156dcc272a50..dcba5233f75b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -31,7 +31,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user'; + final path = r'/user'; Object postBody = user; @@ -96,7 +96,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/createWithArray'; + final path = r'/user/createWithArray'; Object postBody = user; @@ -159,7 +159,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/createWithList'; + final path = r'/user/createWithList'; Object postBody = user; @@ -224,7 +224,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -290,7 +290,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -342,7 +342,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; + return User.fromJson(json.decode(response.body)); } return null; } @@ -367,7 +367,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: password'); } - final path = '/user/login'; + final path = r'/user/login'; Object postBody; @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + return String.fromJson(json.decode(response.body)); } return null; } @@ -433,7 +433,7 @@ class UserApi { /// /// Note: This method returns the HTTP [Response]. Future logoutUserWithHttpInfo() async { - final path = '/user/logout'; + final path = r'/user/logout'; Object postBody; @@ -499,7 +499,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody = user; 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 9f875dba12d6..87a7a36d470b 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 @@ -49,17 +49,6 @@ class ApiClient { Map get authentications => Map.unmodifiable(_authentications); - dynamic deserialize(String json, String targetType, {bool growable}) { - // Remove all spaces. Necessary for reg expressions as well. - targetType = targetType.replaceAll(' ', ''); - - return targetType == 'String' - ? json - : _deserialize(jsonDecode(json), targetType, growable: true == growable); - } - - String serialize(Object obj) => obj == null ? '' : json.encode(obj); - T getAuthentication(String name) { final authentication = _authentications[name]; return authentication is T ? authentication : null; @@ -209,6 +198,17 @@ class ApiClient { throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',); } + dynamic deserialize(String json, String targetType, {bool growable}) { + // Remove all spaces. Necessary for reg expressions as well. + targetType = targetType.replaceAll(' ', ''); + + return targetType == 'String' + ? json + : _deserialize(jsonDecode(json), targetType, growable: true == growable); + } + + String serialize(Object obj) => obj == null ? '' : json.encode(obj); + /// Update query and header parameters based on authentication settings. /// @param authNames The authentications to apply void _updateParamsForAuth( diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart index cdf8eb623c9b..9d2741900e2a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart @@ -31,7 +31,7 @@ class AnotherFakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/another-fake/dummy'; + final path = r'/another-fake/dummy'; Object postBody = modelClient; @@ -84,7 +84,7 @@ class AnotherFakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; + return ModelClient.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart index 24fba9d8349e..bfb3f296cc5b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart @@ -17,7 +17,7 @@ class DefaultApi { /// Performs an HTTP 'GET /foo' operation and returns the [Response]. Future fooGetWithHttpInfo() async { - final path = '/foo'; + final path = r'/foo'; Object postBody; @@ -62,7 +62,7 @@ class DefaultApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'InlineResponseDefault') as InlineResponseDefault; + return InlineResponseDefault.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart index e81da089940d..f483395b4d7d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart @@ -19,7 +19,7 @@ class FakeApi { /// /// Note: This method returns the HTTP [Response]. Future fakeHealthGetWithHttpInfo() async { - final path = '/fake/health'; + final path = r'/fake/health'; Object postBody; @@ -65,7 +65,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'HealthCheckResult') as HealthCheckResult; + return HealthCheckResult.fromJson(json.decode(response.body)); } return null; } @@ -90,7 +90,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/fake/http-signature-test'; + final path = r'/fake/http-signature-test'; Object postBody = pet; @@ -164,7 +164,7 @@ class FakeApi { Future fakeOuterBooleanSerializeWithHttpInfo({ bool body }) async { // Verify required params are set. - final path = '/fake/outer/boolean'; + final path = r'/fake/outer/boolean'; Object postBody = body; @@ -215,7 +215,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'bool') as bool; + return bool.fromJson(json.decode(response.body)); } return null; } @@ -231,7 +231,7 @@ class FakeApi { Future fakeOuterCompositeSerializeWithHttpInfo({ OuterComposite outerComposite }) async { // Verify required params are set. - final path = '/fake/outer/composite'; + final path = r'/fake/outer/composite'; Object postBody = outerComposite; @@ -282,7 +282,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'OuterComposite') as OuterComposite; + return OuterComposite.fromJson(json.decode(response.body)); } return null; } @@ -298,7 +298,7 @@ class FakeApi { Future fakeOuterNumberSerializeWithHttpInfo({ num body }) async { // Verify required params are set. - final path = '/fake/outer/number'; + final path = r'/fake/outer/number'; Object postBody = body; @@ -349,7 +349,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'num') as num; + return num.fromJson(json.decode(response.body)); } return null; } @@ -365,7 +365,7 @@ class FakeApi { Future fakeOuterStringSerializeWithHttpInfo({ String body }) async { // Verify required params are set. - final path = '/fake/outer/string'; + final path = r'/fake/outer/string'; Object postBody = body; @@ -416,7 +416,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + return String.fromJson(json.decode(response.body)); } return null; } @@ -434,7 +434,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: fileSchemaTestClass'); } - final path = '/fake/body-with-file-schema'; + final path = r'/fake/body-with-file-schema'; Object postBody = fileSchemaTestClass; @@ -497,7 +497,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/fake/body-with-query-params'; + final path = r'/fake/body-with-query-params'; Object postBody = user; @@ -563,7 +563,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/fake'; + final path = r'/fake'; Object postBody = modelClient; @@ -616,7 +616,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; + return ModelClient.fromJson(json.decode(response.body)); } return null; } @@ -685,7 +685,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: byte'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -905,7 +905,7 @@ class FakeApi { Future testEnumParametersWithHttpInfo({ List enumHeaderStringArray, String enumHeaderString, List enumQueryStringArray, String enumQueryString, int enumQueryInteger, double enumQueryDouble, List enumFormStringArray, String enumFormString }) async { // Verify required params are set. - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -1048,7 +1048,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requiredInt64Group'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -1142,7 +1142,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requestBody'); } - final path = '/fake/inline-additionalProperties'; + final path = r'/fake/inline-additionalProperties'; Object postBody = requestBody; @@ -1211,7 +1211,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: param2'); } - final path = '/fake/jsonFormData'; + final path = r'/fake/jsonFormData'; Object postBody; @@ -1310,7 +1310,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: context'); } - final path = '/fake/test-query-paramters'; + final path = r'/fake/test-query-paramters'; Object postBody; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart index 66a5c292f0c6..b3fb785d9ad0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart @@ -31,7 +31,7 @@ class FakeClassnameTags123Api { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/fake_classname_test'; + final path = r'/fake_classname_test'; Object postBody = modelClient; @@ -84,7 +84,7 @@ class FakeClassnameTags123Api { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; + return ModelClient.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart index 71abeecfdd9c..5f7324df77b2 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart @@ -29,7 +29,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -94,7 +94,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -166,7 +166,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: status'); } - final path = '/pet/findByStatus'; + final path = r'/pet/findByStatus'; Object postBody; @@ -221,9 +221,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() - .toList(growable: false); + final l = json.decode(response.body); + return List.from(l.map((model) => Pet.fromJson(model))); } return null; } @@ -244,7 +243,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -299,9 +298,8 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'Set') as List) - .cast() - .toSet(); + final l = json.decode(response.body); + return Set.from(l.map((model) => Pet.fromJson(model))); } return null; } @@ -322,7 +320,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -376,7 +374,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; + return Pet.fromJson(json.decode(response.body)); } return null; } @@ -395,7 +393,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -464,7 +462,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}' + final path = r'/pet/{petId}' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -554,7 +552,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: petId'); } - final path = '/pet/{petId}/uploadImage' + final path = r'/pet/{petId}/uploadImage' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -624,7 +622,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; + return ApiResponse.fromJson(json.decode(response.body)); } return null; } @@ -652,7 +650,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requiredFile'); } - final path = '/fake/{petId}/uploadImageWithRequiredFile' + final path = r'/fake/{petId}/uploadImageWithRequiredFile' .replaceAll('{' + 'petId' + '}', petId.toString()); Object postBody; @@ -722,7 +720,7 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; + return ApiResponse.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart index bf83f6a25231..ef9006cd512e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart @@ -31,7 +31,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{order_id}' + final path = r'/store/order/{order_id}' .replaceAll('{' + 'order_id' + '}', orderId.toString()); Object postBody; @@ -89,7 +89,7 @@ class StoreApi { /// /// Note: This method returns the HTTP [Response]. Future getInventoryWithHttpInfo() async { - final path = '/store/inventory'; + final path = r'/store/inventory'; Object postBody; @@ -137,7 +137,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); + return Map.from(json.decode(response.body)); } return null; } @@ -158,7 +158,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: orderId'); } - final path = '/store/order/{order_id}' + final path = r'/store/order/{order_id}' .replaceAll('{' + 'order_id' + '}', orderId.toString()); Object postBody; @@ -212,7 +212,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } return null; } @@ -231,7 +231,7 @@ class StoreApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: order'); } - final path = '/store/order'; + final path = r'/store/order'; Object postBody = order; @@ -282,7 +282,7 @@ class StoreApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; + return Order.fromJson(json.decode(response.body)); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart index 76d477efeb36..ba0ddb7ea863 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart @@ -31,7 +31,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user'; + final path = r'/user'; Object postBody = user; @@ -96,7 +96,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/createWithArray'; + final path = r'/user/createWithArray'; Object postBody = user; @@ -159,7 +159,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/createWithList'; + final path = r'/user/createWithList'; Object postBody = user; @@ -224,7 +224,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -290,7 +290,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: username'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody; @@ -342,7 +342,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; + return User.fromJson(json.decode(response.body)); } return null; } @@ -367,7 +367,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: password'); } - final path = '/user/login'; + final path = r'/user/login'; Object postBody; @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + return String.fromJson(json.decode(response.body)); } return null; } @@ -433,7 +433,7 @@ class UserApi { /// /// Note: This method returns the HTTP [Response]. Future logoutUserWithHttpInfo() async { - final path = '/user/logout'; + final path = r'/user/logout'; Object postBody; @@ -499,7 +499,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: user'); } - final path = '/user/{username}' + final path = r'/user/{username}' .replaceAll('{' + 'username' + '}', username.toString()); Object postBody = user; 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 864e189b21a4..ac9f67d242d4 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 @@ -52,17 +52,6 @@ class ApiClient { Map get authentications => Map.unmodifiable(_authentications); - dynamic deserialize(String json, String targetType, {bool growable}) { - // Remove all spaces. Necessary for reg expressions as well. - targetType = targetType.replaceAll(' ', ''); - - return targetType == 'String' - ? json - : _deserialize(jsonDecode(json), targetType, growable: true == growable); - } - - String serialize(Object obj) => obj == null ? '' : json.encode(obj); - T getAuthentication(String name) { final authentication = _authentications[name]; return authentication is T ? authentication : null; @@ -291,6 +280,17 @@ class ApiClient { throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',); } + dynamic deserialize(String json, String targetType, {bool growable}) { + // Remove all spaces. Necessary for reg expressions as well. + targetType = targetType.replaceAll(' ', ''); + + return targetType == 'String' + ? json + : _deserialize(jsonDecode(json), targetType, growable: true == growable); + } + + String serialize(Object obj) => obj == null ? '' : json.encode(obj); + /// Update query and header parameters based on authentication settings. /// @param authNames The authentications to apply void _updateParamsForAuth( 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 d307b920991d..ececff49c4c8 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 @@ -60,23 +60,18 @@ String parameterToString(dynamic value) { } if (value is EnumClass) { return EnumClassTypeTransformer().encode(value).toString(); - } if (value is OuterEnum) { return OuterEnumTypeTransformer().encode(value).toString(); - } if (value is OuterEnumDefaultValue) { return OuterEnumDefaultValueTypeTransformer().encode(value).toString(); - } if (value is OuterEnumInteger) { return OuterEnumIntegerTypeTransformer().encode(value).toString(); - } if (value is OuterEnumIntegerDefaultValue) { return OuterEnumIntegerDefaultValueTypeTransformer().encode(value).toString(); - } return value.toString(); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart index 7aae686d77b6..9d2741900e2a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart @@ -86,6 +86,6 @@ class AnotherFakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return ModelClient.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart index 0a00c3eca905..bfb3f296cc5b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart @@ -64,6 +64,6 @@ class DefaultApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return InlineResponseDefault.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart index e3f158d136c5..f483395b4d7d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart @@ -67,7 +67,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return HealthCheckResult.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// test http signature authentication @@ -217,7 +217,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return bool.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Test serialization of object with outer number type @@ -284,7 +284,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return OuterComposite.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Test serialization of outer number types @@ -351,7 +351,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return num.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Test serialization of outer string types @@ -418,7 +418,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return String.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// For this test, the body for this request much reference a schema named `File`. @@ -618,7 +618,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return ModelClient.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart index 51ed8e1e8828..b3fb785d9ad0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart @@ -86,6 +86,6 @@ class FakeClassnameTags123Api { if (response.body != null && response.statusCode != HttpStatus.noContent) { return ModelClient.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart index 505856c803e8..5f7324df77b2 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart @@ -224,7 +224,7 @@ class PetApi { final l = json.decode(response.body); return List.from(l.map((model) => Pet.fromJson(model))); } - return Future.value(null); + return null; } /// Finds Pets by tags @@ -301,7 +301,7 @@ class PetApi { final l = json.decode(response.body); return Set.from(l.map((model) => Pet.fromJson(model))); } - return Future.value(null); + return null; } /// Find pet by ID @@ -376,7 +376,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Pet.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Update an existing pet @@ -624,7 +624,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return ApiResponse.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// uploads an image (required) @@ -722,6 +722,6 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return ApiResponse.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart index 289f48d2abe0..ef9006cd512e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(json.decode(response.body)); } - return Future.value(null); + return null; } /// Find purchase order by ID @@ -214,7 +214,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Order.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Place an order for a pet @@ -284,6 +284,6 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Order.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart index e1981eeb471c..ba0ddb7ea863 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart @@ -344,7 +344,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return User.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Logs user into the system @@ -426,7 +426,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return String.fromJson(json.decode(response.body)); } - return Future.value(null); + return null; } /// Logs out current logged in user session From 8ebe1e23758ce6195121676f2ee3b9e075806ba9 Mon Sep 17 00:00:00 2001 From: agilob Date: Wed, 3 Mar 2021 22:02:41 +0000 Subject: [PATCH 3/9] Use Set/List.of --- .../src/main/resources/dart2/api.mustache | 7 ++++++- .../lib/api/pet_api.dart | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index 4b126db8500b..81a4672808c6 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -187,14 +187,19 @@ class {{{classname}}} { if (response.body != null && response.statusCode != HttpStatus.noContent) { {{#isArray}} final l = json.decode(response.body); - return {{{returnType}}}.from(l.map((model) => Pet.fromJson(model))); + return {{{returnType}}}.of(l.map((model) => Pet.fromJson(model))); {{/isArray}} {{^isArray}} {{#isMap}} return {{{returnType}}}.from(json.decode(response.body)); {{/isMap}} {{^isMap}} + {{#isPrimitiveType}} + return json.decode(response.body); + {{/isPrimitiveType}} + {{^isPrimitiveType}} return {{{returnType}}}.fromJson(json.decode(response.body)); + {{/isPrimitiveType}} {{/isMap}} {{/isArray}} } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart index 5f7324df77b2..9f70d83f7eb0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart @@ -222,7 +222,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return List.from(l.map((model) => Pet.fromJson(model))); + return List.of(l.map((model) => Pet.fromJson(model))); } return null; } @@ -299,7 +299,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return Set.from(l.map((model) => Pet.fromJson(model))); + return Set.of(l.map((model) => Pet.fromJson(model))); } return null; } From d8af6e15b1d09e5e977e0a72889fe4b94d8d7b96 Mon Sep 17 00:00:00 2001 From: agilob Date: Thu, 4 Mar 2021 16:07:53 +0000 Subject: [PATCH 4/9] Use returnTypeIsPrimitive in template --- .../src/main/resources/dart2/api.mustache | 8 ++++---- .../lib/api/fake_api.dart | 6 +++--- .../lib/api/user_api.dart | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index 81a4672808c6..c3f4e3cca6bf 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -194,12 +194,12 @@ class {{{classname}}} { return {{{returnType}}}.from(json.decode(response.body)); {{/isMap}} {{^isMap}} - {{#isPrimitiveType}} + {{#returnTypeIsPrimitive}} return json.decode(response.body); - {{/isPrimitiveType}} - {{^isPrimitiveType}} + {{/returnTypeIsPrimitive}} + {{^returnTypeIsPrimitive}} return {{{returnType}}}.fromJson(json.decode(response.body)); - {{/isPrimitiveType}} + {{/returnTypeIsPrimitive}} {{/isMap}} {{/isArray}} } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart index f483395b4d7d..c37a8bb39479 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart @@ -215,7 +215,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return bool.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } @@ -349,7 +349,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return num.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } @@ -416,7 +416,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return String.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart index ba0ddb7ea863..8075bfea1e5a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return String.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } From bb55502be20b0586f3609cfee5dd14d0b888ff80 Mon Sep 17 00:00:00 2001 From: agilob Date: Thu, 4 Mar 2021 19:44:07 +0000 Subject: [PATCH 5/9] Regenerate all templates --- .../petstore/dart2/petstore_client_lib/lib/api/pet_api.dart | 4 ++-- .../dart2/petstore_client_lib/lib/api/user_api.dart | 2 +- .../petstore/dart2/petstore_client_lib/lib/api/pet_api.dart | 4 ++-- .../dart2/petstore_client_lib/lib/api/user_api.dart | 2 +- .../dart2/petstore_client_lib_fake/lib/api/fake_api.dart | 6 +++--- .../dart2/petstore_client_lib_fake/lib/api/pet_api.dart | 4 ++-- .../dart2/petstore_client_lib_fake/lib/api/user_api.dart | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index d6b86a23b3ef..395d1deea44f 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -222,7 +222,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return List.from(l.map((model) => Pet.fromJson(model))); + return List.of(l.map((model) => Pet.fromJson(model))); } return null; } @@ -299,7 +299,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return List.from(l.map((model) => Pet.fromJson(model))); + return List.of(l.map((model) => Pet.fromJson(model))); } return null; } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index d3b3e7106469..8a4a512d5822 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return String.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index 22e121c8ce21..42723a64b435 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -229,7 +229,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return List.from(l.map((model) => Pet.fromJson(model))); + return List.of(l.map((model) => Pet.fromJson(model))); } return null; } @@ -306,7 +306,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return List.from(l.map((model) => Pet.fromJson(model))); + return List.of(l.map((model) => Pet.fromJson(model))); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index dcba5233f75b..5dd4ccdeb16a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return String.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart index f483395b4d7d..c37a8bb39479 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart @@ -215,7 +215,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return bool.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } @@ -349,7 +349,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return num.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } @@ -416,7 +416,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return String.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart index 5f7324df77b2..9f70d83f7eb0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart @@ -222,7 +222,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return List.from(l.map((model) => Pet.fromJson(model))); + return List.of(l.map((model) => Pet.fromJson(model))); } return null; } @@ -299,7 +299,7 @@ class PetApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { final l = json.decode(response.body); - return Set.from(l.map((model) => Pet.fromJson(model))); + return Set.of(l.map((model) => Pet.fromJson(model))); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart index ba0ddb7ea863..8075bfea1e5a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return String.fromJson(json.decode(response.body)); + return json.decode(response.body); } return null; } From e9c760444ce78499f858f20a497c95f9ab7de324 Mon Sep 17 00:00:00 2001 From: agilob Date: Thu, 4 Mar 2021 21:00:40 +0000 Subject: [PATCH 6/9] Fix casting map to Iterable of things --- .../src/main/resources/dart2/api.mustache | 14 +++++++++++--- .../dart2/petstore_client_lib/lib/api/pet_api.dart | 10 ++++++---- .../petstore_client_lib/lib/api/user_api.dart | 2 +- .../dart2/petstore_client_lib/lib/api/pet_api.dart | 10 ++++++---- .../petstore_client_lib/lib/api/user_api.dart | 2 +- .../petstore_client_lib_fake/lib/api/fake_api.dart | 6 +++--- .../petstore_client_lib_fake/lib/api/pet_api.dart | 10 ++++++---- .../petstore_client_lib_fake/lib/api/user_api.dart | 2 +- .../lib/api/fake_api.dart | 6 +++--- .../lib/api/pet_api.dart | 10 ++++++---- .../lib/api/user_api.dart | 2 +- 11 files changed, 45 insertions(+), 29 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index c3f4e3cca6bf..d198c88b706d 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -186,8 +186,16 @@ class {{{classname}}} { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { {{#isArray}} - final l = json.decode(response.body); - return {{{returnType}}}.of(l.map((model) => Pet.fromJson(model))); + {{#uniqueItems}} + return (json.decode(response.body) as List) + .map((i) => {{{returnBaseType}}}.fromJson(i)) + .toSet(); + {{/uniqueItems}} + {{^uniqueItems}} + return (json.decode(response.body) as List) + .map((i) => {{{returnBaseType}}}.fromJson(i)) + .toList(); + {{/uniqueItems}} {{/isArray}} {{^isArray}} {{#isMap}} @@ -195,7 +203,7 @@ class {{{classname}}} { {{/isMap}} {{^isMap}} {{#returnTypeIsPrimitive}} - return json.decode(response.body); + return response.body as {{{returnBaseType}}}; {{/returnTypeIsPrimitive}} {{^returnTypeIsPrimitive}} return {{{returnType}}}.fromJson(json.decode(response.body)); diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index 395d1deea44f..cab952fe0d1a 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -221,8 +221,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return List.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } return null; } @@ -298,8 +299,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return List.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } return null; } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index 8a4a512d5822..4569e3ddfc38 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as String; } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index 42723a64b435..c441744ac661 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -228,8 +228,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return List.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } return null; } @@ -305,8 +306,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return List.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index 5dd4ccdeb16a..8ac5888acc0f 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as String; } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart index c37a8bb39479..35b79a1d478c 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart @@ -215,7 +215,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as bool; } return null; } @@ -349,7 +349,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as num; } return null; } @@ -416,7 +416,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as String; } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart index 9f70d83f7eb0..0e8fe0845349 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart @@ -221,8 +221,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return List.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } return null; } @@ -298,8 +299,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return Set.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toSet(); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart index 8075bfea1e5a..918825ad38ed 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as String; } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart index c37a8bb39479..35b79a1d478c 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart @@ -215,7 +215,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as bool; } return null; } @@ -349,7 +349,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as num; } return null; } @@ -416,7 +416,7 @@ class FakeApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as String; } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart index 9f70d83f7eb0..0e8fe0845349 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart @@ -221,8 +221,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return List.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } return null; } @@ -298,8 +299,9 @@ class PetApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - final l = json.decode(response.body); - return Set.of(l.map((model) => Pet.fromJson(model))); + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toSet(); } return null; } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart index 8075bfea1e5a..918825ad38ed 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart @@ -424,7 +424,7 @@ class UserApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return json.decode(response.body); + return response.body as String; } return null; } From c5496dc939d8dd81a068b3193534b581effa2110 Mon Sep 17 00:00:00 2001 From: agilob Date: Thu, 4 Mar 2021 21:20:44 +0000 Subject: [PATCH 7/9] Add json_serializable to maven modules --- pom.xml | 1 + .../pom.xml | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml diff --git a/pom.xml b/pom.xml index be57c37cbe19..2380cbdf094f 100644 --- a/pom.xml +++ b/pom.xml @@ -1353,6 +1353,7 @@ samples/client/petstore/dart2/petstore samples/openapi3/client/petstore/dart2/petstore_client_lib samples/openapi3/client/petstore/dart2/petstore + samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake samples/client/petstore/dart-dio/petstore_client_lib samples/openapi3/client/petstore/dart-dio/petstore_client_lib samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml new file mode 100644 index 000000000000..204b94074663 --- /dev/null +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml @@ -0,0 +1,73 @@ + + 4.0.0 + org.openapitools + Dart2PetstoreClientJsonSerializableLibTests + pom + 1.0.0-SNAPSHOT + Dart2 Petstore Client with json_serializable Lib + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + export-dartfmt + pre-install-test + + exec + + + export + + DART_FMT_PATH=/usr/local/bin/dartfmt + + + + + pub-get + pre-integration-test + + exec + + + pub + + get + + + + + pub-test + integration-test + + exec + + + pub + + run + test + + + + + + + + From f9e93e29888dae444ae33a05f8bdd774b3121d80 Mon Sep 17 00:00:00 2001 From: agilob Date: Thu, 4 Mar 2021 21:58:13 +0000 Subject: [PATCH 8/9] Run build_runner before pub run test --- .../pom.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml index 204b94074663..708ad4155156 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml @@ -52,6 +52,21 @@ + + pub-build-runner + pre-integration-test + + exec + + + pub + + run + build_runner + build + + + pub-test integration-test From 7759ae1ebc2d8890c477c1868164338202778588 Mon Sep 17 00:00:00 2001 From: agilob Date: Wed, 10 Mar 2021 22:13:42 +0000 Subject: [PATCH 9/9] Return future of type for strong linter mode --- .../src/main/resources/dart2/api.mustache | 2 +- .../dart2/petstore_client_lib/lib/api/pet_api.dart | 8 ++++---- .../petstore_client_lib/lib/api/store_api.dart | 6 +++--- .../petstore_client_lib/lib/api/user_api.dart | 4 ++-- .../dart2/petstore_client_lib/lib/api/pet_api.dart | 12 ++++++------ .../petstore_client_lib/lib/api/store_api.dart | 6 +++--- .../petstore_client_lib/lib/api/user_api.dart | 4 ++-- .../lib/api/another_fake_api.dart | 2 +- .../lib/api/default_api.dart | 2 +- .../petstore_client_lib_fake/lib/api/fake_api.dart | 14 +++++++------- .../lib/api/fake_classname_tags123_api.dart | 2 +- .../petstore_client_lib_fake/lib/api/pet_api.dart | 10 +++++----- .../lib/api/store_api.dart | 6 +++--- .../petstore_client_lib_fake/lib/api/user_api.dart | 4 ++-- .../lib/api/another_fake_api.dart | 2 +- .../lib/api/default_api.dart | 2 +- .../lib/api/fake_api.dart | 14 +++++++------- .../lib/api/fake_classname_tags123_api.dart | 2 +- .../lib/api/pet_api.dart | 10 +++++----- .../lib/api/store_api.dart | 6 +++--- .../lib/api/user_api.dart | 4 ++-- 21 files changed, 61 insertions(+), 61 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index c2ffc434b162..61ecab963b67 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -225,7 +225,7 @@ class {{{classname}}} { {{/isArray}} {{/json_serializable}} } - return Future.value(null); + return Future<{{{returnType}}}>.value(null); {{/returnType}} } {{/operation}} diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index baeed429b7de..c6446b856533 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -225,7 +225,7 @@ class PetApi { .cast() .toList(growable: false); } - return Future.value(null); + return Future>.value(null); } /// Finds Pets by tags @@ -303,7 +303,7 @@ class PetApi { .cast() .toList(growable: false); } - return Future.value(null); + return Future>.value(null); } /// Find pet by ID @@ -378,7 +378,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } - return Future.value(null); + return Future.value(null); } /// Update an existing pet @@ -626,6 +626,6 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart index b80a441e5bb3..490860ed8c2f 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); } - return Future.value(null); + return Future>.value(null); } /// Find purchase order by ID @@ -214,7 +214,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } - return Future.value(null); + return Future.value(null); } /// Place an order for a pet @@ -284,6 +284,6 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index 26fe9da66aa2..f643e2e5dabf 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -344,7 +344,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } - return Future.value(null); + return Future.value(null); } /// Logs user into the system @@ -426,7 +426,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } - return Future.value(null); + return Future.value(null); } /// Logs out current logged in user session diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index 91e4ddf9ec17..2f9bc5863807 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -82,7 +82,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } - return Future.value(null); + return Future.value(null); } /// Deletes a pet @@ -232,7 +232,7 @@ class PetApi { .cast() .toList(growable: false); } - return Future.value(null); + return Future>.value(null); } /// Finds Pets by tags @@ -310,7 +310,7 @@ class PetApi { .cast() .toList(growable: false); } - return Future.value(null); + return Future>.value(null); } /// Find pet by ID @@ -385,7 +385,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } - return Future.value(null); + return Future.value(null); } /// Update an existing pet @@ -455,7 +455,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } - return Future.value(null); + return Future.value(null); } /// Updates a pet in the store with form data @@ -640,6 +640,6 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart index 39000fbee581..76ffaec6faad 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); } - return Future.value(null); + return Future>.value(null); } /// Find purchase order by ID @@ -214,7 +214,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } - return Future.value(null); + return Future.value(null); } /// Place an order for a pet @@ -284,6 +284,6 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index d391f692b150..08847cc2b07d 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -344,7 +344,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } - return Future.value(null); + return Future.value(null); } /// Logs user into the system @@ -426,7 +426,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } - return Future.value(null); + return Future.value(null); } /// Logs out current logged in user session diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart index 6af794734a94..4dbc722ac178 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart @@ -86,6 +86,6 @@ class AnotherFakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart index 837b608bb36d..a75bdc33448e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart @@ -64,6 +64,6 @@ class DefaultApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'InlineResponseDefault') as InlineResponseDefault; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart index 5bd1dcb319bb..d25c1bcd4a5e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart @@ -67,7 +67,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'HealthCheckResult') as HealthCheckResult; } - return Future.value(null); + return Future.value(null); } /// test http signature authentication @@ -217,7 +217,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'bool') as bool; } - return Future.value(null); + return Future.value(null); } /// Test serialization of object with outer number type @@ -284,7 +284,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'OuterComposite') as OuterComposite; } - return Future.value(null); + return Future.value(null); } /// Test serialization of outer number types @@ -351,7 +351,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'num') as num; } - return Future.value(null); + return Future.value(null); } /// Test serialization of outer string types @@ -418,7 +418,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } - return Future.value(null); + return Future.value(null); } /// Test serialization of enum (int) properties with examples @@ -488,7 +488,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'OuterObjectWithEnumProperty') as OuterObjectWithEnumProperty; } - return Future.value(null); + return Future.value(null); } /// For this test, the body for this request much reference a schema named `File`. @@ -688,7 +688,7 @@ class FakeApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; } - return Future.value(null); + return Future.value(null); } /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart index b5ca1a09b0a9..0455f4c68f05 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart @@ -86,6 +86,6 @@ class FakeClassnameTags123Api { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ModelClient') as ModelClient; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart index 71bafa7972c7..eacebcceace3 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart @@ -225,7 +225,7 @@ class PetApi { .cast() .toList(growable: false); } - return Future.value(null); + return Future>.value(null); } /// Finds Pets by tags @@ -303,7 +303,7 @@ class PetApi { .cast() .toSet(); } - return Future.value(null); + return Future>.value(null); } /// Find pet by ID @@ -378,7 +378,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } - return Future.value(null); + return Future.value(null); } /// Update an existing pet @@ -626,7 +626,7 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } - return Future.value(null); + return Future.value(null); } /// uploads an image (required) @@ -724,6 +724,6 @@ class PetApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart index 9b750ca7bf45..91d115d44c83 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); } - return Future.value(null); + return Future>.value(null); } /// Find purchase order by ID @@ -214,7 +214,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } - return Future.value(null); + return Future.value(null); } /// Place an order for a pet @@ -284,6 +284,6 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart index eae48885150a..05ce7f9dec15 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart @@ -344,7 +344,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } - return Future.value(null); + return Future.value(null); } /// Logs user into the system @@ -426,7 +426,7 @@ class UserApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } - return Future.value(null); + return Future.value(null); } /// Logs out current logged in user session diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart index 34723cfc1ed2..29c7103abd37 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/another_fake_api.dart @@ -87,6 +87,6 @@ class AnotherFakeApi { return ModelClient.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart index f8910210e2dd..6295891cd3cc 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/default_api.dart @@ -65,6 +65,6 @@ class DefaultApi { return InlineResponseDefault.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart index e1554c5f0ca5..21c888fa5889 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_api.dart @@ -68,7 +68,7 @@ class FakeApi { return HealthCheckResult.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// test http signature authentication @@ -219,7 +219,7 @@ class FakeApi { return response.body as bool; } - return Future.value(null); + return Future.value(null); } /// Test serialization of object with outer number type @@ -287,7 +287,7 @@ class FakeApi { return OuterComposite.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// Test serialization of outer number types @@ -355,7 +355,7 @@ class FakeApi { return response.body as num; } - return Future.value(null); + return Future.value(null); } /// Test serialization of outer string types @@ -423,7 +423,7 @@ class FakeApi { return response.body as String; } - return Future.value(null); + return Future.value(null); } /// Test serialization of enum (int) properties with examples @@ -494,7 +494,7 @@ class FakeApi { return OuterObjectWithEnumProperty.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// For this test, the body for this request much reference a schema named `File`. @@ -695,7 +695,7 @@ class FakeApi { return ModelClient.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart index 96f44de5f1c4..dc0b394f8fb9 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/fake_classname_tags123_api.dart @@ -87,6 +87,6 @@ class FakeClassnameTags123Api { return ModelClient.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart index 9b8baef0aa31..6c43311b2e8f 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/pet_api.dart @@ -226,7 +226,7 @@ class PetApi { .map((i) => Pet.fromJson(i)) .toList(); } - return Future.value(null); + return Future>.value(null); } /// Finds Pets by tags @@ -305,7 +305,7 @@ class PetApi { .map((i) => Pet.fromJson(i)) .toSet(); } - return Future.value(null); + return Future>.value(null); } /// Find pet by ID @@ -381,7 +381,7 @@ class PetApi { return Pet.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// Update an existing pet @@ -630,7 +630,7 @@ class PetApi { return ApiResponse.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// uploads an image (required) @@ -729,6 +729,6 @@ class PetApi { return ApiResponse.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart index cbd6cbf15202..dd5c2db3528e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/store_api.dart @@ -140,7 +140,7 @@ class StoreApi { return Map.from(json.decode(response.body)); } - return Future.value(null); + return Future>.value(null); } /// Find purchase order by ID @@ -216,7 +216,7 @@ class StoreApi { return Order.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// Place an order for a pet @@ -287,6 +287,6 @@ class StoreApi { return Order.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart index dae705e3c05d..ba21021c9ddb 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/api/user_api.dart @@ -345,7 +345,7 @@ class UserApi { return User.fromJson(json.decode(response.body)); } - return Future.value(null); + return Future.value(null); } /// Logs user into the system @@ -428,7 +428,7 @@ class UserApi { return response.body as String; } - return Future.value(null); + return Future.value(null); } /// Logs out current logged in user session