[BUG][DART] fix nullable nested array item handling
Merged
TI
5mo ago+147+147+012345678901234567890123456789-32-32-01234567890123456789
Summary
This PR fixes Dart generator handling of nullable array items, including nested arrays/maps.
Specifically:
- Preserves nullable item markers in Dart type declarations for nested array/map item schemas (e.g.
List<String?>,List<List<String?>>, built-value equivalents). - Fixes native deserialization template logic for nested array/map branches to avoid nullability/type mismatches.
- Fixes nested complex-array mapping to deserialize each element (
e) instead of incorrectly reusing the full source array.
Validation
Ran targeted Dart tests successfully:
mise x java@temurin-21 -- ./mvnw -pl modules/openapi-generator -am \
-Dtest=org.openapitools.codegen.dart.DartModelTest,org.openapitools.codegen.dart.dio.DartDioModelTest \
-Dsurefire.failIfNoSpecifiedTests=false test
PR checklist
- Read the contribution guidelines.
- Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - File the PR against the correct branch:
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks) - If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having
"fixes #123"present in the PR description) - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Summary by cubic
Preserves nullable item types in nested arrays/maps and fixes native decoding to keep nulls and correct defaults. Prevents type mismatches and bad casts in Dart2 and DartDio built_value models.
-
Bug Fixes
- Preserve nullable item markers in nested type declarations (e.g., List<String?>, List<List<String?>>,
BuiltList<BuiltList<String?>>; alsoMap<String, T?>and collections of nullable items). - Fix native deserialization for nested arrays/maps: map each element
e, cast to nullable element types, use typed const defaults, and passeintolistFromJsonfor complex items.
- Preserve nullable item markers in nested type declarations (e.g., List<String?>, List<List<String?>>,
-
Tests/Samples
- Add tests for nullable items in arrays and nested arrays (incl. complex types) and new
nested-array-nullable-items.yaml. - Update petstore samples and docs to reflect
?in item types and element-wise mapping.
- Add tests for nullable items in arrays and nested arrays (incl. complex types) and new