-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Add support for Optional<T> in Dart generator (both dart and dart-dio) to distinguish absent, null, and present states
#22257
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
eirikb
wants to merge
6
commits into
OpenAPITools:master
Choose a base branch
from
eirikb:feature/eirikb/dart-optional-patch
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
+527
−16
Conversation
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
…io) to distinguish absent, null, and present states
…ns thing for testing (setting both options to "true" for both types)
Member
|
thanks for the pr please follow step 3 to update the samples |
Author
Awesome. I will look into it later today 👍 |
cdfa8fc to
57a8568
Compare
Author
Member
|
👌 let us know if you need any help. |
… - match previously generated setup
wing328
reviewed
Nov 3, 2025
...nerator/src/main/resources/dart/libraries/dio/serialization/json_serializable/class.mustache
Outdated
Show resolved
Hide resolved
Member
|
cc @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08) for review |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

fixes #21826
I saw in the guidelines that you guys don't want too many flags, well, here are two more:
useOptional=true: Enable Optional support all over, andpatchOnly=true: Automatically apply Optional only to only PATCH request schemasThe second one there might seem silly, but it makes a lot of sense to only support absent fields for PATCH.
I had a look at the Java
Nullablething and there it seems it is applied all over, at least when I generated.This might be fine, but not always.
Without the flags the generated stuff should be as before.
This PR require Dart 3 Optional, as I use this to make fields optional.
PR checklist
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)@josh-burton
@yissachar
Some details
Run like this:
Will produce output like this:
Without the
patchOnly=trueflag all fields will beOptional.Thanks :)