Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Jaguar getting error: type 'Future<dynamic>' is not a subtype of type 'Future<List<Depot>>' #40

Open
Plinzen opened this issue Mar 18, 2021 · 2 comments

Comments

@Plinzen
Copy link

Plinzen commented Mar 18, 2021

We switched to flutter 2.0.1 recently and had to rerun our code generation.

We have setup the openapi generator with following data:

pubspec.yaml:

dependencies:
  openapi_generator_annotations: ^3.0.2
  service_api:
    path: api/service_api
  jaguar_retrofit: ^2.8.8
  ...

dev_dependencies:
  openapi_generator: ^3.0.2
  ...

Configuration:

@Openapi(
    additionalProperties: AdditionalProperties(pubName: 'service_api'),
    inputSpecFile: 'spec/openapi-spec.yml',
    generatorName: Generator.jaguar,
    alwaysRun: true,
    overwriteExistingFiles: true,
    outputDirectory: 'api/service_api')
class OpenapiConfig extends OpenapiGeneratorConfig {}

Produced Output with new API

The produced output in the api package is now:

@GenApiClient()
class MyFleetApi extends ApiClient with _$MyFleetApiClient {
    final Route base;
    final Map<String, CodecRepo> converters;
    final Duration timeout;

    MyFleetApi({this.base, this.converters, this.timeout = const Duration(minutes: 2)});

    /// 
    ///
    /// 
    @GetReq(path: "/cc-myfleet/depots")
    Future<List<Depot>> getDepots(
        ) {
        return super.getDepots(

        ).timeout(timeout);
    }

And the corresponding .jretro file:

abstract class _$MyFleetApiClient implements ApiClient {
  final String basePath = "";

  dynamic getDepots() async {
    var req = base.get.path(basePath).path("/cc-myfleet/depots");
    return await req.go(throwOnErr: true);
  }

The jretro file is returning dynamic now and when running the code the following exception is produced:
error: type 'Future<dynamic>' is not a subtype of type 'Future<List<Depot>>'

Previous version for Generator (1.1.4)

The old generator (using flutter 1.x) produced a different output for the .jretro file:

abstract class _$MyFleetApiClient implements ApiClient {
  final String basePath = "";

  Future<List<Depot>> getDepots() async {
    var req = base.get.path(basePath).path("/cc-myfleet/depots");
    return req.go(throwOnErr: true).map(decodeList);
  }

Basically it added a .map call at the end.

Was there a change in the generation for Jaguar?

To link: I found the same issue in a different project: Jaguar-dart/client#68

@gibahjoe
Copy link
Owner

Hello, can you attach a minimal codebase that recreates this issue so that I can have a look. Thanks.

@Plinzen
Copy link
Author

Plinzen commented Mar 22, 2021

Hello,
thanks for your feedback.
Please find the example here, I hope it's sufficient for you to reproduce the issue:

test_flutter.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants