Skip to content

Commit e20ccd4

Browse files
9955 dart-dio-next only remove typed_data import if safe (#9956)
1 parent 2e1b028 commit e20ccd4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioNextClientCodegen.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
322322
}
323323
}
324324

325+
// the MultipartFile handling above changes the type of some parameters from
326+
// `UInt8List`, the default for files, to `MultipartFile`.
327+
//
328+
// The following block removes the required import for Uint8List if it is no
329+
// longer in use.
330+
if (op.allParams.stream().noneMatch(param -> param.dataType.equals("Uint8List"))
331+
&& op.responses.stream().filter(response -> response.dataType != null)
332+
.noneMatch(response -> response.dataType.equals("Uint8List"))) {
333+
// Remove unused imports after processing
334+
op.imports.remove("Uint8List");
335+
}
336+
325337
for (CodegenParameter param : op.bodyParams) {
326338
if (param.isContainer) {
327339
final Map<String, Object> serializer = new HashMap<>();
@@ -333,11 +345,6 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
333345
}
334346
}
335347

336-
if (op.allParams.stream().noneMatch(param -> param.dataType.equals("Uint8List"))) {
337-
// Remove unused imports after processing
338-
op.imports.remove("Uint8List");
339-
}
340-
341348
resultImports.addAll(rewriteImports(op.imports, false));
342349
if (op.getHasFormParams() || op.getHasQueryParams()) {
343350
resultImports.add("package:" + pubName + "/src/api_util.dart");

0 commit comments

Comments
 (0)