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

[dart-dio-next] [BUG] Import mappings are not working #10522

Closed
HerrNiklasRaab opened this issue Oct 4, 2021 · 7 comments · Fixed by #10528
Closed

[dart-dio-next] [BUG] Import mappings are not working #10522

HerrNiklasRaab opened this issue Oct 4, 2021 · 7 comments · Fixed by #10528

Comments

@HerrNiklasRaab
Copy link

HerrNiklasRaab commented Oct 4, 2021

Before reading the issue, the following two things are important:

  • I am supporting fixing this issue with 50€
  • I know that there is the option "dateLibrary: timemachine", but I need to solve it using "import-mappings" because of another reason I don't want to go into here (which should be possible, because I was already able to set up below use case in the backend).

I am running openapi-generator with the following command:

openapi-generator generate -g dart-dio-next \
-i ./api/_config/specs/backend-functional.yml \
-o ./api/backend-api \
-c ./api/_config/specs/backend-functional-config.yml

with the this configuration:

additionalProperties:
  pubName: backend_api
typeMappings:
  object: dynamic
  JsonObject: dynamic
  LocalDate: LocalDate
importMappings:
  LocalDate: "package:time_machine/time_machine.dart"

with this yaml:

CronRunConfiguration:
  properties:
    fakeDate:
      $ref: "#/components/schemas/LocalDate"

LocalDate:
  type: object

which generates the following code:

//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//

import 'package:built_collection/built_collection.dart';
import 'package:backend_api/src/model/local_date.dart'; // Wrong import, expected: "package:time_machine/time_machine.dart"
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'cron_run_configuration.g.dart';

/// CronRunConfiguration
///
/// Properties:
/// * [fakeDate] 
/// * [runCronFor] 
abstract class CronRunConfiguration implements Built<CronRunConfiguration, CronRunConfigurationBuilder> {
    @BuiltValueField(wireName: r'fakeDate')
    LocalDate? get fakeDate;

// ... The rest of the file is not important

what I would have expected is the following:

//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//

import 'package:built_collection/built_collection.dart';
import 'package:time_machine/time_machine.dart'; // This is the important line
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'cron_run_configuration.g.dart';

/// CronRunConfiguration
///
/// Properties:
/// * [fakeDate] 
/// * [runCronFor] 
abstract class CronRunConfiguration implements Built<CronRunConfiguration, CronRunConfigurationBuilder> {
    @BuiltValueField(wireName: r'fakeDate')
    LocalDate? get fakeDate;

// ... The rest of the file is not important

cc @kuhnroyal @wing328 Can you reproduce?

@kuhnroyal
Copy link
Contributor

I added a draft PR, give it a try when you have time.

@HerrNiklasRaab
Copy link
Author

Hey @kuhnroyal,

thanks for the PR, it almost works. Now I get the correct imports!

Unfortunately, I still get a compiler error, because the type LocalDate doesn't have the method "replace" as it's not a model that is generated using built_value:

image

Here is the respective mustache:

image

In my opinion, we have two options:

  1. When using types from import-mappings always default to not making it a model
  2. Introducing a flag like in Java called "--language-specific-primitives=LocalDate". Whenever a type is passed to this flag, it's considered to me not a model.

Don't know which one is better :)

@HerrNiklasRaab
Copy link
Author

@kuhnroyal Increasing to 100 € if fixed until So, 17.Okt

@kuhnroyal
Copy link
Contributor

Updated the PR

@HerrNiklasRaab
Copy link
Author

Working like charm, thanks :) Waiting for your PayPal address, so that I can send you the money, once the PR is merged.

@kuhnroyal
Copy link
Contributor

@HerrNiklasRaab Check the PR commit for the committer email.

@HerrNiklasRaab
Copy link
Author

@kuhnroyal Sent the money, thanks for your help!

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

Successfully merging a pull request may close this issue.

2 participants