-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[dart][dart-dio] Use built_value collection types without string replacement #8153
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] Use built_value collection types without string replacement #8153
Conversation
|
@kuhnroyal no not intentional, more a case of not knowing how to correctly substitute the built collection types. Even though a breaking change I think it's the right change. Nice work :) |
|
@wing328 Is master the correct branch for a breaking change? How should this be documented? |
| importMapping.put("Set", "dart:core"); | ||
| importMapping.put("DateTime", "dart:core"); | ||
|
|
||
| defaultIncludes = new HashSet<>(Collections.singletonList("dart:core")); |
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.
Sets.newHashSet from guava
| } | ||
|
|
||
| @Override | ||
| public String getTypeDeclaration(Schema p) { |
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 you add unit tests to this method?
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.
There are tests for dart and dart-dio that test the type returned for array and map OAS types.
|
|
||
| @Override | ||
| public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) { | ||
| final CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers); |
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 you add unit tests for this method? is it worth to make it more dart-dio specific as the rest of the changes are dart-dio?
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.
Could possibly be moved to the dart-dio generator.
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.
makes sense to keep it here for all darts.
|
I'm not a fan of these changes TBH, it has the following disadvantages I see straight away:
If anything, this should be a runtime flag in custom properties. That said, I much prefer shelf and not planing to use dart-dio, so whatever floats your boat works for me, but please don't put it in main dart. If these changes landed in any generator I use I would be really pissed (as a user) as it completely breaks 100% of cases how I use generated classes in Java and Dart. Autogenerated code are my DTOs and small cached objects, so shared schema and how classes are used between languages absolutely has to be the same, eg. lists and maps have to be mutable. #4865 should be solved in a way that's compatible with other generators, so contributors from scala or python can come to here and be familiars with the generation process. |
|
Any opinion on this @sbu-WBT ? |
IMO this depends on the language/framework features. I usually prefer immutability. Many other generators for languages that have immutable collections by default do the same. Java and Typescript are not some of those as we all know :) If you choose to use this generator, you also choose to use
I would never dream of it. This is here for dart-dio because the used collection classes are part of the same serialization package that is used.
Sounds great and would very much be possible if we could use dart mirrors in Flutter, like we use reflection in Java :) Languages that don't have a form reflection will have the problem of generators being a lot more different to each other because everything that is different has to be expressed in code and can not be weaved in at runtime. It is a great idea to provide a flag to choose a specific serialization framework, as other generators do. But dart-dio doesn't do this yet and it is way out of scope for this issue. |
I didn't mean reflection or mirrors, just content of X1Generator and X2Generator and .mustache files should be as similar as possible to reduce duplication, produce outputs that are more similar. You can swap gson for jackson and as long as there are correct dependencies, it will all work without any fuss. But as above, I'm not familiar with dart-dio, so whatever works for you here. |
agilob
left a comment
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.
Minor change requests not worth effort of a commit, good to go.
Do not use String replacement for built_value collection types.
This fixes #4865 but also changes return/parameter types and would be a breaking change.
I think this is the correct thing to do but the changed parameter types may reduce usability in cases of list body/parameters.
@josh-burton Did you intentionally prevent the return/parameter types from being built_value types? What is your opinion on this?
PR checklist
./bin/generate-samples.shto update all Petstore samples related to your fix. 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.masterCC @ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12)