forked from loafle/openapi-generator-original
[dart-dio] Fixes issues with DateTime import and form date paramaterToString function (#4929)
- due to the addition of the timemachine library, models were importing ‘DateTime’ when using the core library, which is not a valid import. - the parameterToString function was copied from the dart2 generator and had some errors when some enums were classes.
This commit is contained in:
committed by
William Cheng
parent
bb10e8cdd8
commit
f48325ac45
-2
@@ -243,8 +243,6 @@ public class DartDioClientCodegen extends DartClientCodegen {
|
||||
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");
|
||||
|
||||
@@ -23,7 +23,7 @@ class {{classname}} {
|
||||
/// {{notes}}
|
||||
Future<Response{{#returnType}}<{{{returnType}}}>{{/returnType}}>{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "{{{path}}}"{{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}};
|
||||
String path = "{{{path}}}"{{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}};
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> 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}}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -21,7 +21,7 @@ class PetApi {
|
||||
///
|
||||
Future<Response>addPet(Pet body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet";
|
||||
String path = "/pet";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -54,7 +54,7 @@ class PetApi {
|
||||
///
|
||||
Future<Response>deletePet(int petId,{ String apiKey,CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -85,7 +85,7 @@ class PetApi {
|
||||
/// Multiple status values can be provided with comma separated strings
|
||||
Future<Response<List<Pet>>>findPetsByStatus(List<String> status,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet/findByStatus";
|
||||
String path = "/pet/findByStatus";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> 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<Response<List<Pet>>>findPetsByTags(List<String> tags,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet/findByTags";
|
||||
String path = "/pet/findByTags";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -177,7 +177,7 @@ class PetApi {
|
||||
/// Returns a single pet
|
||||
Future<Response<Pet>>getPetById(int petId,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -221,7 +221,7 @@ class PetApi {
|
||||
///
|
||||
Future<Response>updatePet(Pet body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet";
|
||||
String path = "/pet";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -254,7 +254,7 @@ class PetApi {
|
||||
///
|
||||
Future<Response>updatePetWithForm(int petId,{ String name,String status,CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -286,7 +286,7 @@ class PetApi {
|
||||
///
|
||||
Future<Response<ApiResponse>>uploadFile(int petId,{ String additionalMetadata,Uint8List file,CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/pet/{petId}/uploadImage".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
String path = "/pet/{petId}/uploadImage".replaceAll("{" + "petId" + "}", petId.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -299,7 +299,7 @@ class PetApi {
|
||||
|
||||
Map<String, dynamic> formData = {};
|
||||
if (additionalMetadata != null) {
|
||||
formData['additionalMetadata'] = parameterToString(additionalMetadata);
|
||||
formData['additionalMetadata'] = parameterToString(_serializers, additionalMetadata);
|
||||
}
|
||||
if (file != null) {
|
||||
formData['file'] = MultipartFile.fromBytes(file, filename: "file");
|
||||
|
||||
@@ -18,7 +18,7 @@ class StoreApi {
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
Future<Response>deleteOrder(String orderId,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString());
|
||||
String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -48,7 +48,7 @@ class StoreApi {
|
||||
/// Returns a map of status codes to quantities
|
||||
Future<Response<Map<String, int>>>getInventory({ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/store/inventory";
|
||||
String path = "/store/inventory";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> 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<Response<Order>>getOrderById(int orderId,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString());
|
||||
String path = "/store/order/{orderId}".replaceAll("{" + "orderId" + "}", orderId.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -136,7 +136,7 @@ class StoreApi {
|
||||
///
|
||||
Future<Response<Order>>placeOrder(Order body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/store/order";
|
||||
String path = "/store/order";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
|
||||
@@ -18,7 +18,7 @@ class UserApi {
|
||||
/// This can only be done by the logged in user.
|
||||
Future<Response>createUser(User body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user";
|
||||
String path = "/user";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -51,7 +51,7 @@ class UserApi {
|
||||
///
|
||||
Future<Response>createUsersWithArrayInput(List<User> body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/createWithArray";
|
||||
String path = "/user/createWithArray";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -85,7 +85,7 @@ class UserApi {
|
||||
///
|
||||
Future<Response>createUsersWithListInput(List<User> body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/createWithList";
|
||||
String path = "/user/createWithList";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -119,7 +119,7 @@ class UserApi {
|
||||
/// This can only be done by the logged in user.
|
||||
Future<Response>deleteUser(String username,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString());
|
||||
String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -149,7 +149,7 @@ class UserApi {
|
||||
///
|
||||
Future<Response<User>>getUserByName(String username,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString());
|
||||
String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -193,7 +193,7 @@ class UserApi {
|
||||
///
|
||||
Future<Response<String>>loginUser(String username,String password,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/login";
|
||||
String path = "/user/login";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -239,7 +239,7 @@ class UserApi {
|
||||
///
|
||||
Future<Response>logoutUser({ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/logout";
|
||||
String path = "/user/logout";
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
@@ -269,7 +269,7 @@ class UserApi {
|
||||
/// This can only be done by the logged in user.
|
||||
Future<Response>updateUser(String username,User body,{ CancelToken cancelToken, Map<String, String> headers,}) async {
|
||||
|
||||
String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString());
|
||||
String path = "/user/{username}".replaceAll("{" + "username" + "}", username.toString());
|
||||
|
||||
Map<String, dynamic> queryParams = {};
|
||||
Map<String, String> headerParams = Map.from(headers ?? {});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'DateTime';
|
||||
import 'package:built_value/built_value.dart';
|
||||
import 'package:built_value/serializer.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user