Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9955
Closed
Open
Issue created Jul 16, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

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:

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.

Assignee
Assign to
Time tracking