Skip to content

fix(generator): honor effective requiredness for nested FromItem fallbacks#115

Merged
j-d-ha merged 7 commits into
mainfrom
fix/posible-null-for-generated-nested-modles
Apr 20, 2026
Merged

fix(generator): honor effective requiredness for nested FromItem fallbacks#115
j-d-ha merged 7 commits into
mainfrom
fix/posible-null-for-generated-nested-modles

Conversation

@j-d-ha
Copy link
Copy Markdown
Collaborator

@j-d-ha j-d-ha commented Apr 20, 2026

Summary

  • Apply effective requiredness to nested object and nested collection FromItem fallbacks so missing required containers throw instead of silently defaulting.
  • Propagate nested property requiredness into inline helper generation and emit null! for non-nullable optional nested object fallbacks to avoid CS8601 while preserving optional semantics.
  • Update generator snapshots and docs to document nested requiredness behavior, including DefaultRequiredness and dot-notation Required overrides.

Validation

  • dotnet test --project test/LayeredCraft.DynamoMapper.Generators.Tests/LayeredCraft.DynamoMapper.Generators.Tests.csproj
  • dotnet test --project test/LayeredCraft.DynamoMapper.IntegrationTests/LayeredCraft.DynamoMapper.IntegrationTests.csproj

Closes #114.

j-d-ha added 5 commits April 20, 2026 11:19
- Introduced `RequirednessResolver` to determine property requiredness before and after nullability inference.
- Updated `NestedObjectTypeAnalyzer` to use `RequirednessResolver` for configured requiredness resolution.
- Enhanced `PropertyMappingCodeRenderer` to improve fallback handling for required and nullable properties.
- Modified `GetNestedObjectFallback` and `GetNestedCollectionFallback` methods for better requiredness handling.
- Added `Requiredness` to `NestedPropertySpec` for consistent requiredness representation in property specs.
- Updated all generated mappings to use `Requiredness.InferFromNullability` instead of `Requiredness.Optional`.
- Added runtime checks for required attributes and nested properties, throwing `InvalidOperationException` when missing.
- Enhanced test snapshots to reflect stricter requiredness handling in `FromItem` methods.
- Ensured consistency across nested object mappings, collections, and scalar properties in all test cases.
- Updated `publish-preview.yaml` to use `LayeredCraft/devops-templates@v8.1` instead of `@main`.
- Updated `publish-release.yaml` to use `LayeredCraft/devops-templates@v8.1` instead of `@main`.
- Documented `Required` support for nested objects and collections, including dot-notation paths.
- Clarified fallback behavior for missing nested attributes during `FromItem` based on requiredness.
- Updated changelog with fixed fallback behavior respecting effective requiredness.
- Updated documentation to specify that missing required nested containers now throw at runtime.
- Clarified effective requiredness behavior based on `DynamoField.Required` and nullability inference.
- Expanded description of defaults and error handling for nested containers and scalar values.
@github-actions github-actions Bot added the type: fix Bug fix label Apr 20, 2026
j-d-ha added 2 commits April 20, 2026 11:43
- Updated `PropertyMappingCodeRenderer` to include explicit requiredness in rendered code.
- Replaced hardcoded `Requiredness.InferFromNullability` with dynamic `Requiredness.{prop.Requiredness}`.
- Ensured accurate requiredness representation in property mapping logic for better consistency.
- Updated `pr-build.yaml` to use `LayeredCraft/devops-templates@v8.1`.
- Updated `pr-title-check.yaml` to use `LayeredCraft/devops-templates@v8.1`.
- Updated `release-drafter.yaml` to use `LayeredCraft/devops-templates@v8.1`.
Copy link
Copy Markdown
Contributor

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

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

⚠️ The actual code changes look fine, but we need to update the workflows.

Comment thread .github/workflows/publish-preview.yaml
@j-d-ha j-d-ha requested a review from ncipollina April 20, 2026 15:47
Copy link
Copy Markdown
Contributor

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

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

✅ LGTM!

@j-d-ha j-d-ha merged commit 8c12997 into main Apr 20, 2026
6 checks passed
@j-d-ha j-d-ha deleted the fix/posible-null-for-generated-nested-modles branch April 20, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested object deserialization ignores nullability and requiredness

2 participants