[BUG] [Dart-Dio-Next] removes import for typed_data
Created by: MichaelMarner
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
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:
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:
https://github.com/OpenAPITools/openapi-generator/pull/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
https://github.com/OpenAPITools/openapi-generator/pull/9542
Suggest a fix
The import should be removed only if there are no parameters AND no responses with type UInt8List.