diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index ad30ec2cdf03..61ecab963b67 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,47 @@ 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}} + {{#native_serialization}} + {{#isArray}} return (apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as List) .cast<{{{returnBaseType}}}>() .{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}}; - {{/isArray}} - {{^isArray}} - {{#isMap}} + {{/isArray}} + {{^isArray}} + {{#isMap}} return {{{returnType}}}.from(apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}')); - {{/isMap}} - {{^isMap}} + {{/isMap}} + {{^isMap}} return apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as {{{returnType}}}; - {{/isMap}} - {{/isArray}} + {{/isMap}}{{/isArray}}{{/native_serialization}}{{#json_serializable}} + {{#isArray}} + {{#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}} + return {{{returnType}}}.from(json.decode(response.body)); + {{/isMap}} + {{^isMap}} + {{#returnTypeIsPrimitive}} + return response.body as {{{returnBaseType}}}; + {{/returnTypeIsPrimitive}} + {{^returnTypeIsPrimitive}} + return {{{returnType}}}.fromJson(json.decode(response.body)); + {{/returnTypeIsPrimitive}} + {{/isMap}} + {{/isArray}} + {{/json_serializable}} } - return null; + return Future<{{{returnType}}}>.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/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/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..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 @@ -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; @@ -225,7 +225,7 @@ class PetApi { .cast() .toList(growable: false); } - return null; + return Future>.value(null); } /// Finds Pets by tags @@ -244,7 +244,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -303,7 +303,7 @@ class PetApi { .cast() .toList(growable: false); } - return null; + return Future>.value(null); } /// Find pet by ID @@ -322,7 +322,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; @@ -377,8 +377,8 @@ class PetApi { // 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 null; + } + return Future.value(null); } /// Update an existing pet @@ -395,7 +395,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: body'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = body; @@ -464,7 +464,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 +554,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; @@ -625,7 +625,7 @@ class PetApi { // 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 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 1f20bf42f74b..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 @@ -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; @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); } - 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/{orderId}' + final path = r'/store/order/{orderId}' .replaceAll('{' + 'orderId' + '}', orderId.toString()); Object postBody; @@ -213,8 +213,8 @@ class StoreApi { // 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 null; + } + return Future.value(null); } /// Place an order for a pet @@ -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; @@ -283,7 +283,7 @@ class StoreApi { // 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 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 a8a566239ca7..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 @@ -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; @@ -343,8 +343,8 @@ class UserApi { // 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 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; @@ -425,15 +425,15 @@ class UserApi { // 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 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: 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..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 @@ -29,7 +29,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -81,8 +81,8 @@ class PetApi { // 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 null; + } + return Future.value(null); } /// Deletes a pet @@ -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; @@ -232,7 +232,7 @@ class PetApi { .cast() .toList(growable: false); } - return null; + return Future>.value(null); } /// Finds Pets by tags @@ -251,7 +251,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -310,7 +310,7 @@ class PetApi { .cast() .toList(growable: false); } - return null; + return Future>.value(null); } /// Find pet by ID @@ -329,7 +329,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; @@ -384,8 +384,8 @@ class PetApi { // 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 null; + } + return Future.value(null); } /// Update an existing pet @@ -402,7 +402,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -454,8 +454,8 @@ class PetApi { // 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 null; + } + return Future.value(null); } /// Updates a pet in the store with form data @@ -478,7 +478,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 +568,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; @@ -639,7 +639,7 @@ class PetApi { // 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 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 121395c60f04..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 @@ -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; @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); } - 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/{orderId}' + final path = r'/store/order/{orderId}' .replaceAll('{' + 'orderId' + '}', orderId.toString()); Object postBody; @@ -213,8 +213,8 @@ class StoreApi { // 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 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; @@ -283,7 +283,7 @@ class StoreApi { // 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 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 156dcc272a50..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 @@ -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; @@ -343,8 +343,8 @@ class UserApi { // 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 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; @@ -425,15 +425,15 @@ class UserApi { // 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 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_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..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 @@ -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; @@ -85,7 +85,7 @@ class AnotherFakeApi { // 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 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 24fba9d8349e..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 @@ -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; @@ -63,7 +63,7 @@ class DefaultApi { // 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 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 f8fc84ca7f55..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 @@ -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; @@ -66,8 +66,8 @@ class FakeApi { // 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 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; @@ -216,8 +216,8 @@ class FakeApi { // 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 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; @@ -283,8 +283,8 @@ class FakeApi { // 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 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; @@ -350,8 +350,8 @@ class FakeApi { // 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 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; @@ -417,8 +417,8 @@ class FakeApi { // 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 null; + } + return Future.value(null); } /// Test serialization of enum (int) properties with examples @@ -435,7 +435,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: outerObjectWithEnumProperty'); } - final path = '/fake/property/enum-int'; + final path = r'/fake/property/enum-int'; Object postBody = outerObjectWithEnumProperty; @@ -487,8 +487,8 @@ class FakeApi { // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { return apiClient.deserialize(_decodeBodyBytes(response), 'OuterObjectWithEnumProperty') as OuterObjectWithEnumProperty; - } - return null; + } + return Future.value(null); } /// For this test, the body for this request much reference a schema named `File`. @@ -504,7 +504,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; @@ -567,7 +567,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; @@ -633,7 +633,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/fake'; + final path = r'/fake'; Object postBody = modelClient; @@ -687,8 +687,8 @@ class FakeApi { // 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 null; + } + return Future.value(null); } /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -755,7 +755,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: byte'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -975,7 +975,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; @@ -1118,7 +1118,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requiredInt64Group'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -1212,7 +1212,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; @@ -1281,7 +1281,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: param2'); } - final path = '/fake/jsonFormData'; + final path = r'/fake/jsonFormData'; Object postBody; @@ -1380,7 +1380,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..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 @@ -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; @@ -85,7 +85,7 @@ class FakeClassnameTags123Api { // 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 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 71abeecfdd9c..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 @@ -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; @@ -225,7 +225,7 @@ class PetApi { .cast() .toList(growable: false); } - return null; + return Future>.value(null); } /// Finds Pets by tags @@ -244,7 +244,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -303,7 +303,7 @@ class PetApi { .cast() .toSet(); } - return null; + return Future>.value(null); } /// Find pet by ID @@ -322,7 +322,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; @@ -377,8 +377,8 @@ class PetApi { // 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 null; + } + return Future.value(null); } /// Update an existing pet @@ -395,7 +395,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -464,7 +464,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 +554,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; @@ -625,8 +625,8 @@ class PetApi { // 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 null; + } + return Future.value(null); } /// uploads an image (required) @@ -652,7 +652,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; @@ -723,7 +723,7 @@ class PetApi { // 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 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 bf83f6a25231..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 @@ -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; @@ -139,7 +139,7 @@ class StoreApi { if (response.body != null && response.statusCode != HttpStatus.noContent) { return Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); } - 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; @@ -213,8 +213,8 @@ class StoreApi { // 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 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; @@ -283,7 +283,7 @@ class StoreApi { // 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 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 76d477efeb36..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 @@ -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; @@ -343,8 +343,8 @@ class UserApi { // 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 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; @@ -425,15 +425,15 @@ class UserApi { // 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 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_client_lib_fake/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart index 6cc6d8150f26..83da5a1e4829 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; @@ -293,6 +282,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 cdf8eb623c9b..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 @@ -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,9 @@ 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..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 @@ -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,9 @@ 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 f8fc84ca7f55..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 @@ -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,10 @@ 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 +91,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 +165,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 +216,10 @@ 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 response.body as bool; } - return null; + return Future.value(null); } /// Test serialization of object with outer number type @@ -231,7 +233,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 +284,10 @@ 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 +301,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 +352,10 @@ 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 response.body as num; } - return null; + return Future.value(null); } /// Test serialization of outer string types @@ -365,7 +369,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 +420,10 @@ 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 response.body as String; } - return null; + return Future.value(null); } /// Test serialization of enum (int) properties with examples @@ -435,7 +440,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: outerObjectWithEnumProperty'); } - final path = '/fake/property/enum-int'; + final path = r'/fake/property/enum-int'; Object postBody = outerObjectWithEnumProperty; @@ -486,9 +491,10 @@ 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), 'OuterObjectWithEnumProperty') as OuterObjectWithEnumProperty; + + return OuterObjectWithEnumProperty.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`. @@ -504,7 +510,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; @@ -567,7 +573,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; @@ -633,7 +639,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: modelClient'); } - final path = '/fake'; + final path = r'/fake'; Object postBody = modelClient; @@ -686,9 +692,10 @@ 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 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -755,7 +762,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: byte'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -975,7 +982,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; @@ -1118,7 +1125,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: requiredInt64Group'); } - final path = '/fake'; + final path = r'/fake'; Object postBody; @@ -1212,7 +1219,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; @@ -1281,7 +1288,7 @@ class FakeApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: param2'); } - final path = '/fake/jsonFormData'; + final path = r'/fake/jsonFormData'; Object postBody; @@ -1380,7 +1387,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..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 @@ -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,9 @@ 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..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 @@ -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,12 @@ 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); + + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) + .toList(); } - return null; + return Future>.value(null); } /// Finds Pets by tags @@ -244,7 +245,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: tags'); } - final path = '/pet/findByTags'; + final path = r'/pet/findByTags'; Object postBody; @@ -299,11 +300,12 @@ 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() + + return (json.decode(response.body) as List) + .map((i) => Pet.fromJson(i)) .toSet(); } - return null; + return Future>.value(null); } /// Find pet by ID @@ -322,7 +324,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 +378,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), 'Pet') as Pet; + + return Pet.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// Update an existing pet @@ -395,7 +398,7 @@ class PetApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: pet'); } - final path = '/pet'; + final path = r'/pet'; Object postBody = pet; @@ -464,7 +467,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 +557,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 +627,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), 'ApiResponse') as ApiResponse; + + return ApiResponse.fromJson(json.decode(response.body)); } - return null; + return Future.value(null); } /// uploads an image (required) @@ -652,7 +656,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 +726,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); } } 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..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 @@ -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,10 @@ 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 +159,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 +213,10 @@ 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 +233,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 +284,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); } } 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..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 @@ -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,10 @@ 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 +368,7 @@ class UserApi { throw ApiException(HttpStatus.badRequest, 'Missing required param: password'); } - final path = '/user/login'; + final path = r'/user/login'; Object postBody; @@ -424,16 +425,17 @@ 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 response.body as String; } - 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 +501,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 84a1288bc299..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,143 +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 'OuterObjectWithEnumProperty': - return OuterObjectWithEnumProperty.fromJson(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(); } 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..708ad4155156 --- /dev/null +++ b/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/pom.xml @@ -0,0 +1,88 @@ + + 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-build-runner + pre-integration-test + + exec + + + pub + + run + build_runner + build + + + + + pub-test + integration-test + + exec + + + pub + + run + test + + + + + + + +