[dart] Fix compile error in inline enum properties with "default" vaues(#22120)#22165
[dart] Fix compile error in inline enum properties with "default" vaues(#22120)#22165wing328 merged 1 commit intoOpenAPITools:masterfrom
Conversation
| - "2" | ||
| - '' | ||
| - 'value_one' | ||
| - 'value_two' |
There was a problem hiding this comment.
shall we keep the same test schemas and add new one covered by this PR instead?
There was a problem hiding this comment.
The previous test schemas were actually incorrect — they were missing an allOf, which caused inconsistent behavior.
I fixed that and renamed the test and parameters to make them consistent with the other tests in the project.
Additionally, I added a new test that covers a separate case where the enum is defined inline.
There was a problem hiding this comment.
why not keep the same
enum:
- ""
- "1"
- "2"
?
why do you need to change the enum values to something else?
wouldn't "1", "2" still work with the fix?
There was a problem hiding this comment.
why do you need to change the enum values to something else?
These enum values are not similar to the values of other enums in other test cases.
This change only affects consistency.
Leaving these changes unchanged will not change anything.
wouldn't "1", "2" still work with the fix?
Its will work.
I can return these values back if it is important.
There was a problem hiding this comment.
ok. let's given it a try with what you've so far.
thanks again for the PR
This PR solves the problem described in #22120.
This change fixes a regression in the Dart Dio generator where enum defaults were emitted as raw strings, which broke inline enums while previously working defaults on referenced EnumClass definitions
The template now constructs defaults through the generated enum type (
{{enumName}}.valueOf(...)) wheneverenumNameis available and falls back to the literal value otherwise. With this approach both referenced enums (e.g., schemas usingallOf/$ref) and inline enums receive fully-typed defaults during builder initialization.I also added test cases.
@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)
@wing328