-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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][dart-dio] Next-gen dart-dio generator #8869
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
I'm having a heck of a time getting this to build locally. I have tried to build with openjdk8 and oracle java 14.0.2.
|
I think I got it running enough to generate my project by running something like |
Hmm, the error looks like I might have messed something up with the templates but the example generates, not sure.
That is the way I am using it outside of the build in examples. |
Just stumbled upon this, looks promising - good job 👍 I was wondering if it would be easier to use |
Good question and one I have evaluated before. But this new version of the generator will allow to add different serialization libraries in the future. You are welcome to start working on a freezed implementation and see where that leads you. |
This solves the problem of not being able to serialize null.
} | ||
|
||
class BasicAuthInterceptor extends AuthInterceptor { | ||
Map<String, BasicAuthInfo> authInfo = {}; | ||
Map<String, BasicAuthInfo> authInfo = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this was just a copy/paste job from dart-dio.
import 'package:dio/dio.dart'; | ||
import 'package:{{pubName}}/src/auth/auth.dart'; | ||
|
||
class OAuthInterceptor extends AuthInterceptor { | ||
Map<String, String> tokens = {}; | ||
Map<String, String> tokens = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final for consistency?
This is much faster than individual files. The committed samples should be formatted since Dart is very opinionated and it makes diffs in PRs much easier to read. Due to this, we also need to format in CI, otherwise there is a git diff.
If the additional library timemachine is not used, the Date format cannot be used. A complete DateTime string is always generated. Is it possible to distinguish between Date and DateTime like in the "normal" Dart generator? As an example the following formatter is used in the Dart generator: |
Could you open an issue for that and call me and @kuhnroyal? |
Don't think this is possible unfortunately, but I have not tried. built_value can only have one serializer per class and date/datetime is the same class |
I will open an issue later today and tag you. The implementation might be possible by extending Iso8601DateTimeSerializer in combination with FullType parameters. The DateTime serializer would be called in each case. Once as now and once with the parameter date or similar. |
lets not comment here again, we will lose context of the problem. call us to the issue |
@kuhnroyal |
@TimWhiting I already have a version that uses freezed. I just need to clean it up a bit and raise a PR which probably @kuhnroyal could validate. I am using normal enum and seems to work well. Will create a PR today... 😄 |
@Abhilash-Chandran I'm happy to test it on my apis to see if it makes sense. Can you push what you have so far to a branch? |
@Abhilash-Chandran I'd be interested in this as well. |
@dastein1 @Abhilash-Chandran Here is a link to @Abhilash-Chandran's branch: If anyone wants to try to get the rebased branch working & a PR opened, that would probably be a good place to start. I'll see what time I have, but I can't make any promises. I was hoping to see Here are the instructions I got from @Abhilash-Chandran to run his branch:
with the generator_config.yaml containing the additional property to enable freezed. additionalProperties:
serializationLibrary: freezed |
I saw some simiallar issues while building after rebasing. I will try to rework on this from the fresh branch. But no promises yet. Especially the way the templates are referred to has changed since I began working on this. So my idea is to port my changes directly on a fresh fork and hence avoid a host of other errors. |
@Abhilash-Chandran I did end up copying the json_serializable/api folder to the freezed folder. That seemed to be the only major change needed to get it to compile & generate valid dart files. However, I have not tried using the generated api yet. The changes are on my branch. |
WIP!
This is work in progress but examples compile and tests run locally. This needs an updated Dart version in CI.
Description
This PR establishes a next-gen dart-dio generator with breaking changes around null-safety which can not be implemented in backwards-compatible ways.
Features & changes
DioError
dart format
in CI (waiting on dart format --set-exit-if-changed not really setting the status code dart-lang/sdk#44582)TODO
null
with built_value (Support serializing null on a per field basis - nullable vs required google/built_value.dart#912)unused_import
analyzer warning in polymorph model classesPR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x