Skip to content

[dart] Fix enum defaults, Object arrays, and nullable required assertions in native serialization#23027

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
EddieRydell:fix/dart-native-serialization-bugs
Feb 23, 2026
Merged

[dart] Fix enum defaults, Object arrays, and nullable required assertions in native serialization#23027
wing328 merged 2 commits intoOpenAPITools:masterfrom
EddieRydell:fix/dart-native-serialization-bugs

Conversation

@EddieRydell
Copy link
Copy Markdown
Contributor

@EddieRydell EddieRydell commented Feb 22, 2026

Summary

Fixes three bugs in the Dart native serialization codegen:

  • Enum default values emit string literals instead of enum constructorsfromJson fallback generated ?? 'value_one' instead of ?? const EnumType._('value_one'), causing a type mismatch
  • Object.listFromJson() doesn't existObject was not in languageSpecificPrimitives, so Object-typed arrays generated invalid Object.listFromJson() calls instead of cast<Object>()
  • Required+nullable fields incorrectly assert non-null — the requiredKeys.forEach assertion block asserted json[key] != null for all required fields, including nullable ones

Fixes #13459, fixes #20152, fixes #20296

Changes

File Change
AbstractDartCodegen.java Add "Object" to languageSpecificPrimitives (consistent with DartDio)
native_class.mustache Wrap enum default with const {enumName}._() constructor
native_class.mustache Replace requiredKeys.forEach with per-property assertions respecting isNullable
DartClientCodegenTest.java Add integration tests for all three fixes

Test plan

  • New integration tests generate Dart code from a test spec and assert correct output
  • All 109 Dart tests pass (native + DartDio)
  • Regenerated samples

Summary by cubic

Fixes three Dart native serialization bugs: enum default deserialization, Object arrays, and required+nullable field assertions. Also updates docs to list Object as a language primitive in Dart and Dart-Dio.

  • Bug Fixes

    • Enum defaults in fromJson now use const Enum._('value') instead of a string literal.
    • Object-typed arrays no longer call Object.listFromJson(); Object is treated as a primitive and uses cast().
    • Required nullable fields assert presence only; non-null checks apply only to non-nullable required fields.
    • Migration

      • Regenerate Dart native clients to pick up the fixes. No manual changes needed.
    • Written for commit 1a9997f. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 60 files

@wing328 wing328 merged commit 17a28eb into OpenAPITools:master Feb 23, 2026
17 checks passed
@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 23, 2026

thanks for the PR which has been merged

@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 23, 2026

FYI @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)

@wing328 wing328 added this to the 7.21.0 milestone Feb 23, 2026
davidricodias pushed a commit to davidricodias/openapi-generator that referenced this pull request Mar 11, 2026
…ions in native serialization (OpenAPITools#23027)

* fix(dart): fix enum defaults, Object arrays, and nullable required assertions in native serialization

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

Projects

None yet

2 participants