-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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-next] Refactor to decouple serialization from networking #15485
Conversation
…nto separate directories WIP serialization repo implmentation
Update:
The plan is that after this PR, we split the |
…to refactor-dart-dio
…to refactor-dart-dio
@kuhnroyal I have updated the PR to introduce a new generator |
* use much newer exec plugin * run pub via dart sub command
{{#imports}}import '{{.}}'; | ||
{{/imports}} | ||
|
||
part '{{classFilename}}.g.dart'; |
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.
This currently fails when there are no inline enums
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.
yes, I am aware of that, and I am working on a fix rn and completing the generator changes
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.
Nice, ill see if I have time to test during the FlutterCon days.
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.
@ahmednfwela Do you have a fix for this?
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.
@kuhnroyal yes, but I am a little busy for a couple of days
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.
Can I help here in anyway?
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.
I am pushing a fix for it today , sorry for the delay
I pushed a fix for the Also some work needs to be done on the nullability areas. |
I loosely followed the built_value tickets. I assume this is regarding default values? Can we move forward without those for now? |
@kuhnroyal we can just use normal dart primitives for the api definations, and only use built_value for models |
What is the point of supporting built list and built value? |
@NotHolst well, built_value was the first immutability library to come out for dart, but now that dart has grown up, it's starting to fall behind. one of its perks though is the separation of serializers and models into different classes, which allows a plugin style for serialization. |
@ahmednfwela okay, sounds like a niche use for most of us who just want api codegeneration that works out of the box. |
@NotHolst I am honestly starting to go this way too, I have been arguing with so I will be removing |
const SerializationRepositoryBase(); | ||
|
||
FutureOr<Object?> serialize<T extends Object?>(T src, TypeInfo inputTypeInfo, {Object? context,}); | ||
FutureOr<T> deserialize<T extends Object?>(Object? value, TypeInfo targetTypeInfo, {Object? context,}); |
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.
Making these async seems overkill and increases complexity in other places.
What is your use case here?
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.
@kuhnroyal you might want to offset the (de)serialization process to another isolate like the dart generator does
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.
I see. Does it make sense to provide both options so that we can use the sync access especially for parameter serialization etc.?
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.
@kuhnroyal that was actually my plan since I sometimes need the serialization logic in places where I can't use async
required EnumQueryDoubleEnum enumQueryDouble, | ||
required BuiltList<ModelEnumClass> enumQueryModelArray, | ||
BuiltList<InnerEnum> enumFormStringArray = r'$', | ||
EnumFormStringEnum enumFormString = r'-efg', |
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.
Need to find a way to generate these defaults correctly.
And also collection default values.
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.
with built_value
, you can't since you need const constructors, so I plan on removing support for built_value
entirely and focus on json_serializable
/freezed
} | ||
|
||
|
||
class InnerEnum extends EnumClass { |
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.
This is missing its values, not sure why.
// ignore_for_file: unused_element | ||
import 'package:openapi/src/model/fruit_type.dart'; | ||
import 'package:openapi/src/model/apple_any_of_disc.dart'; | ||
import 'package:openapi/src/model/banana_any_of_disc.dart'; |
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.
These 2 imports do not exist, something is wrong with the anyof generation.
any updates to this? |
|
@NotHolst Sorry I have been extremely busy lately with my professional work, that I don't have that much time to spare on opensource projects, I will however try to finish this PR since we will have to depend on it eventually. |
I'm following up on this a month later to make sure it doesn't go stale. I'm willing to put in the work, but i'll need a briefing on current progress, goals/milestones and potential roadblocks. |
Also, would like to know what is outstanding to move this forward? |
…to refactor-dart-dio
@ahmednfwela when you've time, can you please PM me via Slack? Thanks. |
Hello everyone following this PR, I have started a new PR that contains a better version of this generator that has no 3rd party dependencies for serialization/modelling, thus avoiding all the blocking I have faced. I will be closing this PR in favor of: |
Introduce a new
dart-next
generator.fixes #15477
as discussed in the above issue, this PR completely decouples the networking layer from the serialization/deserialization layer.
It also minimizes the serialization/networking layer's footprint, to simplify adding new serialization/networking options (like freezed #13047, or http)
It introduces new classes
TypeInfo
- similar tobuilt_value
'sFullType
, but adapted to all serializersSerializationRepositoryBase
- the base class to handle all serialization operations in the API layerBuiltValueJsonRepository
-built_value
's implementation ofSerializationRepositoryBase
JsonSerializableRepository
-json_serializable
's implementation ofSerializationRepositoryBase
Raw
version of each API that is decoupled from serialization/deserialization, and can handle any data format (not only json)PR 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
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08) @bahag-chandrana