diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java index 29c81b823ce4..7a4886f5ed43 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -243,8 +243,6 @@ public void processOpts() { additionalProperties.put("core", "true"); typeMapping.put("Date", "DateTime"); typeMapping.put("date", "DateTime"); - importMapping.put("DateTime", "DateTime"); - importMapping.put("OffsetDateTime", "DateTime"); } else if ("timemachine".equals(dateLibrary)) { additionalProperties.put("timeMachine", "true"); typeMapping.put("date", "LocalDate"); diff --git a/modules/openapi-generator/src/main/resources/dart-dio/api.mustache b/modules/openapi-generator/src/main/resources/dart-dio/api.mustache index e25eb930e83e..5b7ace703e8a 100644 --- a/modules/openapi-generator/src/main/resources/dart-dio/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart-dio/api.mustache @@ -23,7 +23,7 @@ class {{classname}} { /// {{notes}} Future{{/returnType}}>{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}CancelToken cancelToken, Map headers,}) async { - String path = "{{{path}}}"{{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}}; + String path = "{{{path}}}"{{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}}; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -46,7 +46,7 @@ class {{classname}} { {{#isMultipart}} {{^isFile}} if ({{paramName}} != null) { - formData['{{baseName}}'] = parameterToString({{paramName}}); + formData['{{baseName}}'] = parameterToString(_serializers, {{paramName}}); } {{/isFile}} {{#isFile}} diff --git a/modules/openapi-generator/src/main/resources/dart-dio/api_util.mustache b/modules/openapi-generator/src/main/resources/dart-dio/api_util.mustache index eedad9166fd4..e99530f6c39e 100644 --- a/modules/openapi-generator/src/main/resources/dart-dio/api_util.mustache +++ b/modules/openapi-generator/src/main/resources/dart-dio/api_util.mustache @@ -1,18 +1,14 @@ +import 'dart:convert'; + +import 'package:built_value/serializer.dart'; + /// Format the given parameter object into string. -String parameterToString(dynamic value) { - if (value == null) { - return ''; - } else if (value is DateTime) { - return value.toUtc().toIso8601String(); - {{#models}} - {{#model}} - {{#isEnum}} - } else if (value is {{classname}}) { - return {{classname}}TypeTransformer().encode(value).toString(); - {{/isEnum}} - {{/model}} - {{/models}} - } else { - return value.toString(); - } +String parameterToString(Serializers serializers, dynamic value) { + if (value == null) { + return ''; + } else if (value is String || value is num) { + return value.toString(); + } else { + return json.encode(serializers.serialize(value)); + } } \ No newline at end of file diff --git a/samples/client/petstore/dart-dio/README.md b/samples/client/petstore/dart-dio/README.md index c9c0f49b85ed..ceda34066bc0 100644 --- a/samples/client/petstore/dart-dio/README.md +++ b/samples/client/petstore/dart-dio/README.md @@ -57,36 +57,36 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*PetApi* | [**addPet**](doc\/PetApi.md#addpet) | **post** /pet | Add a new pet to the store -*PetApi* | [**deletePet**](doc\/PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet -*PetApi* | [**findPetsByStatus**](doc\/PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status -*PetApi* | [**findPetsByTags**](doc\/PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags -*PetApi* | [**getPetById**](doc\/PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID -*PetApi* | [**updatePet**](doc\/PetApi.md#updatepet) | **put** /pet | Update an existing pet -*PetApi* | [**updatePetWithForm**](doc\/PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data -*PetApi* | [**uploadFile**](doc\/PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | [**deleteOrder**](doc\/StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID -*StoreApi* | [**getInventory**](doc\/StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status -*StoreApi* | [**getOrderById**](doc\/StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID -*StoreApi* | [**placeOrder**](doc\/StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet -*UserApi* | [**createUser**](doc\/UserApi.md#createuser) | **post** /user | Create user -*UserApi* | [**createUsersWithArrayInput**](doc\/UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array -*UserApi* | [**createUsersWithListInput**](doc\/UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array -*UserApi* | [**deleteUser**](doc\/UserApi.md#deleteuser) | **delete** /user/{username} | Delete user -*UserApi* | [**getUserByName**](doc\/UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name -*UserApi* | [**loginUser**](doc\/UserApi.md#loginuser) | **get** /user/login | Logs user into the system -*UserApi* | [**logoutUser**](doc\/UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session -*UserApi* | [**updateUser**](doc\/UserApi.md#updateuser) | **put** /user/{username} | Updated user +*PetApi* | [**addPet**](doc//PetApi.md#addpet) | **post** /pet | Add a new pet to the store +*PetApi* | [**deletePet**](doc//PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet +*PetApi* | [**findPetsByStatus**](doc//PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status +*PetApi* | [**findPetsByTags**](doc//PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags +*PetApi* | [**getPetById**](doc//PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID +*PetApi* | [**updatePet**](doc//PetApi.md#updatepet) | **put** /pet | Update an existing pet +*PetApi* | [**updatePetWithForm**](doc//PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**uploadFile**](doc//PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**deleteOrder**](doc//StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**getInventory**](doc//StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status +*StoreApi* | [**getOrderById**](doc//StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**placeOrder**](doc//StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet +*UserApi* | [**createUser**](doc//UserApi.md#createuser) | **post** /user | Create user +*UserApi* | [**createUsersWithArrayInput**](doc//UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**createUsersWithListInput**](doc//UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array +*UserApi* | [**deleteUser**](doc//UserApi.md#deleteuser) | **delete** /user/{username} | Delete user +*UserApi* | [**getUserByName**](doc//UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name +*UserApi* | [**loginUser**](doc//UserApi.md#loginuser) | **get** /user/login | Logs user into the system +*UserApi* | [**logoutUser**](doc//UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session +*UserApi* | [**updateUser**](doc//UserApi.md#updateuser) | **put** /user/{username} | Updated user ## Documentation For Models - - [ApiResponse](doc\/ApiResponse.md) - - [Category](doc\/Category.md) - - [Order](doc\/Order.md) - - [Pet](doc\/Pet.md) - - [Tag](doc\/Tag.md) - - [User](doc\/User.md) + - [ApiResponse](doc//ApiResponse.md) + - [Category](doc//Category.md) + - [Order](doc//Order.md) + - [Pet](doc//Pet.md) + - [Tag](doc//Tag.md) + - [User](doc//User.md) ## Documentation For Authorization diff --git a/samples/client/petstore/dart-dio/lib/api/pet_api.dart b/samples/client/petstore/dart-dio/lib/api/pet_api.dart index 2458f5ffe927..7078df59692a 100644 --- a/samples/client/petstore/dart-dio/lib/api/pet_api.dart +++ b/samples/client/petstore/dart-dio/lib/api/pet_api.dart @@ -21,7 +21,7 @@ class PetApi { /// FutureaddPet(Pet body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/pet"; + String path = "/pet"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -54,7 +54,7 @@ class PetApi { /// FuturedeletePet(int petId,{ String apiKey,CancelToken cancelToken, Map headers,}) async { - String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); + String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -85,7 +85,7 @@ class PetApi { /// Multiple status values can be provided with comma separated strings Future>>findPetsByStatus(List status,{ CancelToken cancelToken, Map headers,}) async { - String path = "/pet/findByStatus"; + String path = "/pet/findByStatus"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -131,7 +131,7 @@ class PetApi { /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. Future>>findPetsByTags(List tags,{ CancelToken cancelToken, Map headers,}) async { - String path = "/pet/findByTags"; + String path = "/pet/findByTags"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -177,7 +177,7 @@ class PetApi { /// Returns a single pet Future>getPetById(int petId,{ CancelToken cancelToken, Map headers,}) async { - String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); + String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -221,7 +221,7 @@ class PetApi { /// FutureupdatePet(Pet body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/pet"; + String path = "/pet"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -254,7 +254,7 @@ class PetApi { /// FutureupdatePetWithForm(int petId,{ String name,String status,CancelToken cancelToken, Map headers,}) async { - String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); + String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -286,7 +286,7 @@ class PetApi { /// Future>uploadFile(int petId,{ String additionalMetadata,Uint8List file,CancelToken cancelToken, Map headers,}) async { - String path = "/pet/{petId}/uploadImage".replaceAll("{" + "petId" + "}", petId.toString()); + String path = "/pet/{petId}/uploadImage".replaceAll("{" + "petId" + "}", petId.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -299,7 +299,7 @@ class PetApi { Map formData = {}; if (additionalMetadata != null) { - formData['additionalMetadata'] = parameterToString(additionalMetadata); + formData['additionalMetadata'] = parameterToString(_serializers, additionalMetadata); } if (file != null) { formData['file'] = MultipartFile.fromBytes(file, filename: "file"); diff --git a/samples/client/petstore/dart-dio/lib/api/store_api.dart b/samples/client/petstore/dart-dio/lib/api/store_api.dart index 8be8835b6b0f..abbe73be27c2 100644 --- a/samples/client/petstore/dart-dio/lib/api/store_api.dart +++ b/samples/client/petstore/dart-dio/lib/api/store_api.dart @@ -18,7 +18,7 @@ class StoreApi { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors FuturedeleteOrder(String orderId,{ CancelToken cancelToken, Map headers,}) async { - String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString()); + String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -48,7 +48,7 @@ class StoreApi { /// Returns a map of status codes to quantities Future>>getInventory({ CancelToken cancelToken, Map headers,}) async { - String path = "/store/inventory"; + String path = "/store/inventory"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -92,7 +92,7 @@ class StoreApi { /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions Future>getOrderById(int orderId,{ CancelToken cancelToken, Map headers,}) async { - String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString()); + String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -136,7 +136,7 @@ class StoreApi { /// Future>placeOrder(Order body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/store/order"; + String path = "/store/order"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); diff --git a/samples/client/petstore/dart-dio/lib/api/user_api.dart b/samples/client/petstore/dart-dio/lib/api/user_api.dart index bb2c84d2e8c4..a2d2d3189a32 100644 --- a/samples/client/petstore/dart-dio/lib/api/user_api.dart +++ b/samples/client/petstore/dart-dio/lib/api/user_api.dart @@ -18,7 +18,7 @@ class UserApi { /// This can only be done by the logged in user. FuturecreateUser(User body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user"; + String path = "/user"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -51,7 +51,7 @@ class UserApi { /// FuturecreateUsersWithArrayInput(List body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user/createWithArray"; + String path = "/user/createWithArray"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -85,7 +85,7 @@ class UserApi { /// FuturecreateUsersWithListInput(List body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user/createWithList"; + String path = "/user/createWithList"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -119,7 +119,7 @@ class UserApi { /// This can only be done by the logged in user. FuturedeleteUser(String username,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString()); + String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -149,7 +149,7 @@ class UserApi { /// Future>getUserByName(String username,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString()); + String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -193,7 +193,7 @@ class UserApi { /// Future>loginUser(String username,String password,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user/login"; + String path = "/user/login"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -239,7 +239,7 @@ class UserApi { /// FuturelogoutUser({ CancelToken cancelToken, Map headers,}) async { - String path = "/user/logout"; + String path = "/user/logout"; Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); @@ -269,7 +269,7 @@ class UserApi { /// This can only be done by the logged in user. FutureupdateUser(String username,User body,{ CancelToken cancelToken, Map headers,}) async { - String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString()); + String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString()); Map queryParams = {}; Map headerParams = Map.from(headers ?? {}); diff --git a/samples/client/petstore/dart-dio/lib/api_util.dart b/samples/client/petstore/dart-dio/lib/api_util.dart index 3a05d24f7b99..e99530f6c39e 100644 --- a/samples/client/petstore/dart-dio/lib/api_util.dart +++ b/samples/client/petstore/dart-dio/lib/api_util.dart @@ -1,10 +1,14 @@ +import 'dart:convert'; + +import 'package:built_value/serializer.dart'; + /// Format the given parameter object into string. -String parameterToString(dynamic value) { - if (value == null) { - return ''; - } else if (value is DateTime) { - return value.toUtc().toIso8601String(); - } else { - return value.toString(); - } +String parameterToString(Serializers serializers, dynamic value) { + if (value == null) { + return ''; + } else if (value is String || value is num) { + return value.toString(); + } else { + return json.encode(serializers.serialize(value)); + } } \ No newline at end of file diff --git a/samples/client/petstore/dart-dio/lib/model/order.dart b/samples/client/petstore/dart-dio/lib/model/order.dart index 01f93031072e..4838d56a1d7b 100644 --- a/samples/client/petstore/dart-dio/lib/model/order.dart +++ b/samples/client/petstore/dart-dio/lib/model/order.dart @@ -1,4 +1,3 @@ - import 'DateTime'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart';