OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.29k stars 6.44k forks source link

[BUG][dart-dio] syntax error stopping build_runner from completing #12306

Open lukepighetti opened 2 years ago

lukepighetti commented 2 years ago

dart-dio fails to generate the Twitter v2 API spec. The outputted code has syntax errors that does not allow build_runner to generate the final pieces of code

https://api.twitter.com/2/openapi.json

openapi.json.zip

openapi-generator-cli 5.4.0
  commit : 4a36be7
  built  : 2022-01-31T05:31:36Z
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
openapi-generator generate -i spec.json -g dart-dio -o dart_dio_client
cd dart_dio_client
dart pub get
dart run build_runner build --delete-conflicting-outputs
[SEVERE] built_value_generator:built_value on test/spaces_api_test.dart:

Bad state: Unexpected diagnostics:
/Users/lukepighetti/development/flutter/flutter/bin/cache/dart-sdk/lib/core/int.dart:167:18 - Operator declarations must be preceded by the keyword 'operator'.
/Users/lukepighetti/development/flutter/flutter/bin/cache/dart-sdk/lib/core/int.dart:167:16 - Methods must have an explicit list of parameters.
/Users/lukepighetti/development/flutter/flutter/bin/cache/dart-sdk/lib/core/int.dart:167:18 - A function body must be provided.

Related to:

lukepighetti commented 2 years ago

Just manually updated all deps to the following:

name: openapi
version: 1.0.0
description: OpenAPI API client
homepage: homepage

environment:
  sdk: '>=2.7.0 <3.0.0'

dependencies:
  dio: ^4.0.6
  built_value: ^8.2.3
  built_collection: ^5.1.1

dev_dependencies:
  built_value_generator: ^8.2.3
  build_runner: ^2.1.10
  test: ^1.21.1

This allowed build_runner to complete, but there are numerous syntax issues. It looks like the implementing classes are not overriding methods with appropriate arguments or return types resulting in static analysis errors.

Screen Shot 2022-05-06 at 9 32 46 PM
Milou6 commented 2 years ago

Can confirm that I was previously using dart_dio_next without issues, but now trying to switch to the new dart-dio the generator is stuck on building.

I tried @lukepighetti 's suggestion of updating deps, but I get the following :

Running "flutter pub get" in brand-service-sdk...                   5.0s
Failed to build build_runner:build_runner:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:build_runner_core
 - package:io
 - package:logging
 - package:build_runner
 - package:build
 - package:glob
 - package:crypto
 - package:watcher
 - package:build_config
 - package:build_resolvers
 - package:timing
 - package:graphs
 - package:package_config
 - package:yaml
 - package:code_builder
 - package:dart_style
 - package:build_daemon
 - package:http_multi_server
 - package:shelf
 - package:pub_semver
 - package:pubspec_parse
 - package:analyzer
 - package:convert
 - package:built_value
 - package:built_collection
 - package:http_parser
 - package:shelf_web_socket
 - package:web_socket_channel
 - package:_fe_analyzer_shared
 - package:checked_yaml
 - package:matcher
 - package:quiver
 - package:fixnum
 - package:cli_util

For solutions, see https://dart.dev/go/unsound-null-safety
../../../../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.11.1+1/bin/build_runner.dart:89:9: Warning: Operand of null-aware operation '?.' has type 'StreamSubscription<dynamic>' which excludes null.
 - 'StreamSubscription' is from 'dart:async'.
  await logListener?.cancel();
        ^
pub finished with exit code 1
hanayashiki commented 2 years ago

I have changed my pubspec.yaml into the following, because of incompatibilities with sdk 2.12.0

name: xxxx
version: 1.0.0
description: OpenAPI API client
homepage: homepage

environment:
  sdk: '>=2.7.0 <3.0.0'

dependencies:
  dio: '^4.0.0'
  built_value: '>=8.0.0 <9.0.0'
  built_collection: '>=5.0.0 <6.0.0'

dev_dependencies:
  built_value_generator: '>=8.0.0 <9.0.0'
  build_runner: any
  test: '>=1.21.1 <2.0.0'
  analyzer: 4.1.0
dependency_overrides:
  meta: 1.8.0

It finally generates the code, but Dio 4.x.x simply doesn't work with this library:

    final _response = await _dio.request<dynamic>(
      _request.path,
      data: _bodyData,
      options: _request,
    );
image

This library seems out-of-date and cannot work with the latest version of Dio and dart sdk anymore

TobiasHintiLotzApp commented 2 years ago

I have the exact same issue. When I use dart-dio-next in my command for generating the openapi the build works but I get a parse error as soon as I use my API calls. I've already created an issue on this with more details. Does anybody know different openapi generators for dart (with null safety)?

kuhnroyal commented 1 year ago

I think nullsafety are solved by now. Please re-check and close the issue if so.

lukepighetti commented 1 year ago

dio is deprecated, this generation target should also be deprecated or migrated to diox

kuhnroyal commented 1 year ago

@lukepighetti You are working with outdated information. diox is archived and dio: 5.0.0 was released. See #14675