mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
fix[dart]: send ISO8601 dates
This commit is contained in:
parent
d5ced7df38
commit
6d6cfb4984
@ -17,7 +17,6 @@ class ApiClient {
|
||||
|
||||
final dson = new Dartson.JSON()
|
||||
..addTransformer(new DateTimeParser(), DateTime);
|
||||
final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
final _RegList = new RegExp(r'^List<(.*)>$');
|
||||
final _RegMap = new RegExp(r'^Map<String,(.*)>$');
|
||||
@ -33,24 +32,6 @@ class ApiClient {
|
||||
_defaultHeaderMap[key] = value;
|
||||
}
|
||||
|
||||
/// Format the given Date object into string.
|
||||
String formatDate(DateTime date) {
|
||||
return _dateFormatter.format(date);
|
||||
}
|
||||
|
||||
/// Format the given parameter object into string.
|
||||
String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return '';
|
||||
} else if (param is DateTime) {
|
||||
return formatDate(param);
|
||||
} else if (param is List) {
|
||||
return (param).join(',');
|
||||
} else {
|
||||
return param.toString();
|
||||
}
|
||||
}
|
||||
|
||||
dynamic _deserialize(dynamic value, String targetType) {
|
||||
try {
|
||||
switch (targetType) {
|
||||
|
@ -11,7 +11,7 @@ Iterable<QueryParam> _convertParametersForCollectionFormat(
|
||||
if (name == null || name.isEmpty || value == null) return params;
|
||||
|
||||
if (value is! List) {
|
||||
params.add(new QueryParam(name, '$value'));
|
||||
params.add(new QueryParam(name, _parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -23,11 +23,22 @@ Iterable<QueryParam> _convertParametersForCollectionFormat(
|
||||
: collectionFormat; // default: csv
|
||||
|
||||
if (collectionFormat == "multi") {
|
||||
return values.map((v) => new QueryParam(name, '$v'));
|
||||
return values.map((v) => new QueryParam(name, _parameterToString(v)));
|
||||
}
|
||||
|
||||
String delimiter = _delimiters[collectionFormat] ?? ",";
|
||||
|
||||
params.add(new QueryParam(name, values.join(delimiter)));
|
||||
params.add(new QueryParam(name, values.map((v)=>_parameterToString(v)).join(delimiter)));
|
||||
return params;
|
||||
}
|
||||
|
||||
/// 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();
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import 'package:http/browser_client.dart';{{/browserClient}}
|
||||
import 'package:http/http.dart';
|
||||
import 'package:dartson/dartson.dart';
|
||||
import 'package:dartson/transformers/date_time.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
part 'api_client.dart';
|
||||
part 'api_helper.dart';
|
||||
|
@ -4,7 +4,6 @@ description: {{pubDescription}}
|
||||
dependencies:
|
||||
http: '>=0.11.1 <0.12.0'
|
||||
dartson: "^0.2.4"
|
||||
intl: ">=0.12.4"
|
||||
|
||||
dev_dependencies:
|
||||
guinness: '^0.1.17'
|
||||
|
@ -6,7 +6,6 @@ import 'package:http/browser_client.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:dartson/dartson.dart';
|
||||
import 'package:dartson/transformers/date_time.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
part 'api_client.dart';
|
||||
part 'api_helper.dart';
|
||||
|
@ -17,7 +17,6 @@ class ApiClient {
|
||||
|
||||
final dson = new Dartson.JSON()
|
||||
..addTransformer(new DateTimeParser(), DateTime);
|
||||
final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
final _RegList = new RegExp(r'^List<(.*)>$');
|
||||
final _RegMap = new RegExp(r'^Map<String,(.*)>$');
|
||||
@ -32,24 +31,6 @@ class ApiClient {
|
||||
_defaultHeaderMap[key] = value;
|
||||
}
|
||||
|
||||
/// Format the given Date object into string.
|
||||
String formatDate(DateTime date) {
|
||||
return _dateFormatter.format(date);
|
||||
}
|
||||
|
||||
/// Format the given parameter object into string.
|
||||
String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return '';
|
||||
} else if (param is DateTime) {
|
||||
return formatDate(param);
|
||||
} else if (param is List) {
|
||||
return (param).join(',');
|
||||
} else {
|
||||
return param.toString();
|
||||
}
|
||||
}
|
||||
|
||||
dynamic _deserialize(dynamic value, String targetType) {
|
||||
try {
|
||||
switch (targetType) {
|
||||
|
@ -11,7 +11,7 @@ Iterable<QueryParam> _convertParametersForCollectionFormat(
|
||||
if (name == null || name.isEmpty || value == null) return params;
|
||||
|
||||
if (value is! List) {
|
||||
params.add(new QueryParam(name, '$value'));
|
||||
params.add(new QueryParam(name, _parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -23,11 +23,22 @@ Iterable<QueryParam> _convertParametersForCollectionFormat(
|
||||
: collectionFormat; // default: csv
|
||||
|
||||
if (collectionFormat == "multi") {
|
||||
return values.map((v) => new QueryParam(name, '$v'));
|
||||
return values.map((v) => new QueryParam(name, _parameterToString(v)));
|
||||
}
|
||||
|
||||
String delimiter = _delimiters[collectionFormat] ?? ",";
|
||||
|
||||
params.add(new QueryParam(name, values.join(delimiter)));
|
||||
params.add(new QueryParam(name, values.map((v)=>_parameterToString(v)).join(delimiter)));
|
||||
return params;
|
||||
}
|
||||
|
||||
/// 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();
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ description: Swagger API client
|
||||
dependencies:
|
||||
http: '>=0.11.1 <0.12.0'
|
||||
dartson: "^0.2.4"
|
||||
intl: ">=0.12.4"
|
||||
|
||||
dev_dependencies:
|
||||
guinness: '^0.1.17'
|
||||
|
Loading…
Reference in New Issue
Block a user