Skip to content

Conversation

chizhanov
Copy link
Contributor

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(...)) whenever enumName is available and falls back to the literal value otherwise. With this approach both referenced enums (e.g., schemas using allOf/$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

- "2"
- ''
- 'value_one'
- 'value_two'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we keep the same test schemas and add new one covered by this PR instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants