openapi-generator-dart
openapi-generator-dart copied to clipboard
Using Jaguar getting error: type 'Future<dynamic>' is not a subtype of type 'Future<List<Depot>>'
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: https://github.com/Jaguar-dart/client/issues/68
Hello, can you attach a minimal codebase that recreates this issue so that I can have a look. Thanks.
Hello, thanks for your feedback. Please find the example here, I hope it's sufficient for you to reproduce the issue: