-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Dart codegen bug fixes: honor prefix/suffix, handle operation return types, replaces Object with Map #12574
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
Open
jeffmikels
wants to merge
7
commits into
OpenAPITools:master
Choose a base branch
from
jeffmikels:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dart codegen bug fixes: honor prefix/suffix, handle operation return types, replaces Object with Map #12574
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8d7107
added returnInnerType for container types, made Dart generator recogn…
jeffmikels ad6a3fc
Merge branch 'OpenAPITools:master' into master
jeffmikels f1babda
added returnInnerType for container types, made Dart generator recogn…
jeffmikels 7fd619d
added returnInnerType for container types, made Dart generator recogn…
jeffmikels 57a5a27
added returnInnerType for container types, made Dart generator recogn…
jeffmikels 3afd82a
making sure modelNamePrefix is honored throughout the library
jeffmikels fc9037e
fixed the default option for API_CLIENT_NAME when testing the DartDio…
jeffmikels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what extra information does
returnInnerType
add ?Uh oh!
There was an error while loading. Please reload this page.
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.
As an example, when the
returnType
isList<Map<String, String>>
thenreturnBaseType
will beList
but the dart code, to be type safe, will want to call.cast<Map<String, String>>()
. Therefore, we need to exposeMap<String, String>
to the template somehow.In this case,
returnInnerType
will contain the string 'Map<String, String>'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.
why use this instead of just items property?
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.
The generated code in the earlier version was simply wrong. Dart would fail to compile it under certain cases.
To see where it matters, look at the template in
dart2
namedapi.mustache
on line 180. In this PR, you'll see this:Previously, it said this:
In most cases, that is fine, but consider the following example from the openApi document from the Mattermost project. There is this api endpoint:
In this case, the
returnType
will beList<Map<String, List<GroupWithSchemeAdmin>>>
but thereturnBaseType
will beMap
which will result in the following Dart code:However, this code will not compile because the
.cast
operation coerces all list objects toMap
which is the same asMap<dynamic, dynamic>
and is LESS SPECIFIC thanMap<String, List<GroupWithSchemeAdmin>>
. The compiler can't guarantee that this cast will be valid and so the code won't compile.By adding the
returnInnerType
variable to thejava
class and by changing the mustache template, the new code will look like this:This code will compile.
Why not use the items property?
It's true that
items.dataType
contains the exact same data, but that value is not available toapi.mustache
in the context where it is needed.This value must be exposed in the same context as
returnType
.