- 
          
 - 
                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
base: master
Are you sure you want to change the base?
Conversation
…io) to distinguish absent, null, and present states
…ns thing for testing (setting both options to "true" for both types)
| 
           thanks for the pr please follow step 3 to update the samples  | 
    
          
 Awesome. I will look into it later today 👍  | 
    
cdfa8fc    to
    57a8568      
    Compare
  
    | 
           👌 let us know if you need any help.  | 
    
… - match previously generated setup
| {{^isBinary}} | ||
| @JsonKey( | ||
| {{^required}}{{#useOptional}} @OptionalConverter() | ||
| {{/useOptional}}{{/required}} @JsonKey( | 
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.
if you put these tags in separate lines, it should avoid empty line breaks
e.g.
{{^required}}
{{#useOptional}}
  @OptionalConverter()
{{/useOptional}}
{{/required}}
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.
Looks like that worked! Thanks. Looks better

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 :)