Bug Report Checklist
Description
The Dart-dio-next generator removes the import for dart:typed_data, required for UInt8List, if there are no parameters that have a UInt8List type:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java#L336
This causes invalid code generation for operations that return a UInt8List. Since the check linked above only looks at parameters, not at return types.
This line was added (by the looks) because file parameter types are by default UInt8List, but are changed to MultipartFile under certain conditions. The goal being to remove the import if it is nolonger required, because all instances of UInt8List have been replaced.
openapi-generator version
Testing against master. This is a regression, introduced here:
#9542
OpenAPI declaration file content or url
Example JSON:
{
"swagger": "2.0",
"info": {
"version": "1.10.0"
},
"paths": {
"exampleFileResponse": {
"get": {
"summary": "Downloads a file",
"operationId": ".exampleFileResponse",
"parameters": [],
"responses": {
"200": {
"description": "Downloads the file",
"schema": {
"description": "Downloads the file",
"type": "file"
}
}
}
}
}
}
}
Will generate and API matching the file attached. As can be seen, the function definition is:
Future<Response<Uint8List>> exampleFileResponse({
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
})
but the import for dart:typed_data is missing.
default_api.dart.txt
Generation Details
Example above can be generated with the following command:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i test_swagger.json \
-g dart-dio-next \
-o output \
--skip-validate-spec
Related issues/PRs
#9542
Suggest a fix
The import should be removed only if there are no parameters AND no responses with type UInt8List.
Bug Report Checklist
Description
The Dart-dio-next generator removes the import for
dart:typed_data, required forUInt8List, if there are no parameters that have aUInt8Listtype:https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java#L336
This causes invalid code generation for operations that return a UInt8List. Since the check linked above only looks at parameters, not at return types.
This line was added (by the looks) because
fileparameter types are by defaultUInt8List, but are changed toMultipartFileunder certain conditions. The goal being to remove the import if it is nolonger required, because all instances ofUInt8Listhave been replaced.openapi-generator version
Testing against
master. This is a regression, introduced here:#9542
OpenAPI declaration file content or url
Example JSON:
{ "swagger": "2.0", "info": { "version": "1.10.0" }, "paths": { "exampleFileResponse": { "get": { "summary": "Downloads a file", "operationId": ".exampleFileResponse", "parameters": [], "responses": { "200": { "description": "Downloads the file", "schema": { "description": "Downloads the file", "type": "file" } } } } } } }Will generate and API matching the file attached. As can be seen, the function definition is:
but the import for
dart:typed_datais missing.default_api.dart.txt
Generation Details
Example above can be generated with the following command:
Related issues/PRs
#9542
Suggest a fix
The import should be removed only if there are no parameters AND no responses with type UInt8List.