Skip to content

[BUG] [Dart-Dio-Next] removes import for typed_data #9955

@MichaelMarner

Description

@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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions