You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating a Get request with content-type application/octet-stream or text/event-stream the output returns a MultipartFile instead of the expected Stream<Uint8List>.
The generated code then calls the deserialize which fails with the exception Cannot deserialize.
I expect the generated method to return Stream<Uint8List>.
/// openAiChatSessionMessageRetrieve /// /// /// Parameters: /// * [id] /// * [messageId] /// * [cancelToken] - A [CancelToken] that can be used to cancel the operation /// * [headers] - Can be used to add additional headers to the request /// * [extras] - Can be used to add flags to the request /// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response /// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress /// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress /// /// Returns a [Future] containing a [Response] with a [MultipartFile] as data /// Throws [DioException] if API call or serialization failsFuture<Response<MultipartFile>> openAiChatSessionMessageRetrieve({
requiredString id,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path =r'/api/open-ai/session/{id}/'
.replaceAll('{'r'id''}', id.toString())
final _options =Options(
method:r'GET',
responseType:ResponseType.bytes,
headers:<String, dynamic>{
...?headers,
},
extra:<String, dynamic>{
...?extra,
},
validateStatus: validateStatus,
);
final _response =await _dio.request<Object>(
_path,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
MultipartFile? _responseData;
try {
final rawData = _response.data;
_responseData = rawData ==null?null:deserialize<MultipartFile, MultipartFile>(rawData, 'MultipartFile',
growable:true); // CRASH ---> deserialize cannot create MultipartFile
} catch (error, stackTrace) {
throwDioException(
requestOptions: _response.requestOptions,
response: _response,
type:DioExceptionType.unknown,
error: error,
stackTrace: stackTrace,
);
}
returnResponse<MultipartFile>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}
deserializer:
final _regList =RegExp(r'^List<(.*)>$');
final _regSet =RegExp(r'^Set<(.*)>$');
final _regMap =RegExp(r'^Map<String,(.*)>$');
ReturnTypedeserialize<ReturnType, BaseType>(dynamic value, String targetType,
{bool growable =true}) {
switch (targetType) {
case'String':return'$value'asReturnType;
case'int':return (value isint? value :int.parse('$value')) asReturnType;
case'bool':if (value isbool) {
return value asReturnType;
}
final valueString ='$value'.toLowerCase();
return (valueString =='true'|| valueString =='1') asReturnType;
case'double':return (value isdouble? value :double.parse('$value')) asReturnType;
// Rest of models, but no MultipartFiledefault:RegExpMatch? match;
if (value isList&& (match = _regList.firstMatch(targetType)) !=null) {
targetType = match![1]!; // ignore: parameter_assignmentsreturn value
.map<BaseType>((dynamic v) =>deserialize<BaseType, BaseType>(
v, targetType,
growable: growable))
.toList(growable: growable) asReturnType;
}
if (value isSet&& (match = _regSet.firstMatch(targetType)) !=null) {
targetType = match![1]!; // ignore: parameter_assignmentsreturn value
.map<BaseType>((dynamic v) =>deserialize<BaseType, BaseType>(
v, targetType,
growable: growable))
.toSet() asReturnType;
}
if (value isMap&& (match = _regMap.firstMatch(targetType)) !=null) {
targetType = match![1]!.trim(); // ignore: parameter_assignmentsreturnMap<String, BaseType>.fromIterables(
value.keys asIterable<String>,
value.values.map((dynamic v) =>deserialize<BaseType, BaseType>(
v, targetType,
growable: growable)),
) asReturnType;
}
break;
}
throwException('Cannot deserialize');
}
Generation Details
open-generator-config.ymal
# Config options for the dart-dio generatorpubName: app_apipubVersion: 0.0.1pubDescription: "App API"dateLibrary: coreserializationLibrary: json_serializableequalityCheckMethod: equatable
Bug Report Checklist
Description
When generating a Get request with content-type
application/octet-stream
ortext/event-stream
the output returns aMultipartFile
instead of the expectedStream<Uint8List>
.The generated code then calls the
deserialize
which fails with the exceptionCannot deserialize
.I expect the generated method to return
Stream<Uint8List>
.openapi-generator version
openapi-generator-cli 7.12.0-SNAPSHOT
OpenAPI declaration file content or url
ymal schema:
Output:
deserializer:
Generation Details
open-generator-config.ymal
Steps to reproduce
run
The text was updated successfully, but these errors were encountered: