gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
128 stars 34 forks source link

openapi_generator 4.10.0 still uses DioError for serialization exceptions #92

Open bgenidy opened 1 year ago

bgenidy commented 1 year ago

Description of the bug

I upgraded my openapi_generator to 4.10.0 which uses Dio 5.0. Since Dio 5.0 switched to using DioException and deprecated DioError the generated code now can throw two types of exceptions.

  1. if the request itself fails it will now get DioException since that is what Dio 5.0 and above use
  2. if the failure happens in the serialization flow the auto gen code is still using DioError
try {
      const _responseType = FullType(ChatMessagesResponse);
      _responseData = _serializers.deserialize(
        _response.data!,
        specifiedType: _responseType,
      ) as ChatMessagesResponse;

    } catch (error, stackTrace) {
      throw DioError(
        requestOptions: _response.requestOptions,
        response: _response,
        type: DioErrorType.unknown,
        error: error,
        stackTrace: stackTrace,
      );
    }

Steps to reproduce

  1. install the latest openapi_generator https://pub.dev/packages/openapi_generator/versions/4.10.0
  2. generate an openapi spec using the dart dio option, here is the command I use openapi-generator generate -i ./swagger.json -g dart-dio -o ./dartdio-codegen
  3. look at any of the generated apis in dartdio-codegen/lib/src/api to see the use of the deprecated DioError class

Expected behavior

The use of DioError and DioErrorType for serialization errors should be switched to DioException and DioExceptionType

Logs

No response

Screenshots

No response

Platform

macOS

Library version

4.10.0

Flutter version

3.10.4

Flutter channel

stable

Additional context

flutter info

[✓] Flutter (Channel stable, 3.10.4, on macOS 13.1 22C65 darwin-arm64, locale en-US)
    • Flutter version 3.10.4 on channel stable at /Users/bg/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 682aa387cf (3 weeks ago), 2023-06-05 18:04:56 -0500
    • Engine revision 2a3401c9bb
    • Dart version 3.0.3
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/bg/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A309
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 114.0.5735.133

[✓] Network resources
    • All expected network resources are available.

• No issues found!
quyenvsp commented 1 year ago

will fix with https://github.com/gibahjoe/openapi-generator-dart/pull/107 hope it complete soon.

For now you can fix by force using Dio 5.1.2