Skip to content

fix(codegen): isRequired() returns false for choice block properties#608

Merged
david-waltermire merged 1 commit intometaschema-framework:developfrom
david-waltermire:feature/604-choice-required
Dec 31, 2025
Merged

fix(codegen): isRequired() returns false for choice block properties#608
david-waltermire merged 1 commit intometaschema-framework:developfrom
david-waltermire:feature/604-choice-required

Conversation

@david-waltermire
Copy link
Contributor

@david-waltermire david-waltermire commented Dec 31, 2025

Summary

  • Fixes isRequired() to return false for properties inside Metaschema choice blocks
  • Properties in choice blocks are conditionally required (requirement depends on which branch is taken)
  • Generated getters/setters now have correct @Nullable/@NonNull annotations
  • Javadocs on generated setters now document nullability behavior

Changes

  • AbstractNamedModelInstanceTypeInfo.isRequired() now checks for choiceId before returning true
  • Updated IPropertyTypeInfo.isRequired() Javadoc to document choice block behavior
  • Enhanced setter Javadoc generation to indicate when null values are acceptable
  • Regenerated all bootstrap binding classes with correct annotations

Test plan

  • New unit tests verify isRequired() returns false for choice properties
  • Unit tests cover boundary conditions (minOccurs, maxOccurs, collections)
  • Full CI build passes: mvn clean install -PCI -Prelease
  • Regenerated bindings show correct annotation changes (e.g., METASCHEMA.getRootName() now returns @Nullable)

Resolves #604

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed handling of required/optional field status for properties inside Metaschema choice blocks. Fields within choice blocks are now correctly treated as optional for null-safety.
  • New Features

    • Added public accessor methods to retrieve metaschema data from constraint classes.
  • Documentation

    • Updated development workflow documentation to clarify precedence rules for project-specific conventions.

✏️ Tip: You can customize this high-level summary in your review settings.

…etaschema-framework#604)

Properties inside Metaschema choice blocks are conditionally required -
their requirement depends on which choice branch is taken. This fix
ensures isRequired() returns false for all choice block members,
resulting in @nullable annotations on generated getters/setters.

Changes:
- AbstractNamedModelInstanceTypeInfo.isRequired() now checks choiceId
- Updated Javadoc on IPropertyTypeInfo.isRequired() documenting behavior
- Enhanced setter Javadoc generation for nullability documentation
- Regenerated bootstrap binding classes with correct annotations

Resolves metaschema-framework#604
@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

📝 Walkthrough

Walkthrough

The PR implements a fix for the isRequired() method in code generator type-info classes to correctly treat fields inside Metaschema <choice> blocks as optional, preventing false NullPointerException exceptions in generated code. It includes documentation updates, new unit tests, Javadoc refinements, and regeneration of binding classes.

Changes

Cohort / File(s) Summary
Core Logic Implementation
databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfo.java
Added conditional short-circuit in isRequired() returning false when property is inside a choice block (getChoiceId() != null), before evaluating minOccurs logic.
Type Info Interface Javadoc Updates
databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/IPropertyTypeInfo.java, INamedInstanceTypeInfo.java, INamedModelInstanceTypeInfo.java
Updated isRequired() Javadoc to document that properties in choice blocks always evaluate as optional. Enhanced setter Javadoc to conditionally describe nullability: required/collection properties state "non-null", optional properties state "or {@code null} to clear".
Documentation & Workflow
.claude/rules/development-workflow.md, PRDs/20251231-choice-required-fix/PRD.md, PRDs/20251231-choice-required-fix/implementation-plan.md
Added PRD documenting the issue and technical design. Updated workflow rules clarifying that project-specific conventions override skill defaults.
Test Implementation
databind/src/test/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfoTest.java
New unit test file verifying isRequired() behavior across scenarios: required/optional properties outside choice blocks, properties inside choice blocks with/without choiceId set, and collection properties.
Generated Binding Classes — Core Metaschema
databind/src/main/java/gov/nist/secauto/metaschema/databind/config/binding/MetaschemaBindings.java, MetaschemaBindingsModule.java, package-info.java, databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ (30\+ files)
Extensive formatting, annotation alignment, and Javadoc reflow across regenerated binding classes. Added public getMetaschemaData() accessors to FieldConstraints, FlagConstraints, KeyConstraintField. Minor null-safety annotation and documentation updates. No functional logic changes.
Generated Test Bindings
metaschema-testing/src/main/java/gov/nist/secauto/metaschema/model/testing/testsuite/ (10\+ files)
Formatting, annotation alignment, and Javadoc reflow in regenerated test suite binding classes. Minor documentation tweaks for nullability in setters. No behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The core logic change in isRequired() is localized and straightforward, but requires careful validation against the choice-block semantics. Javadoc updates across multiple interfaces add context-dependent review points. The extensive regeneration of binding classes with primarily formatting/annotation changes is homogeneous and lower-risk; however, the addition of new getMetaschemaData() accessors and setter Javadoc nullability descriptions warrant verification for consistency.

Possibly related PRs

Suggested reviewers

  • aj-stein-gsa
  • wandmagic

Poem

🐰 Choices made, now null-safe and bright,
Fields inside choice blocks? No false required-plight!
Generated code flows clean and true,
Choice-aware isRequired() — our fix rings through! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR contains extensive formatting and documentation changes (whitespace, Javadoc rewrapping, annotation reformatting) across generated binding classes that go beyond the stated objective of fixing isRequired() behavior. Separate formatting/documentation changes from functional changes. The core isRequired() fix should be cleanly isolated from widespread cosmetic regeneration of binding classes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: fixing isRequired() to return false for properties inside choice blocks, which is the core objective.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #604: isRequired() now returns false for choice properties, Javadoc is updated, and setter Javadoc indicates nullability.
Docstring Coverage ✅ Passed Docstring coverage is 99.03% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PMD (7.19.0)
databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/INamedInstanceTypeInfo.java

[ERROR] Cannot load ruleset pmd/category/java/custom.xml: Cannot resolve rule/ruleset reference 'pmd/category/java/custom.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

databind/src/main/java/gov/nist/secauto/metaschema/databind/model/metaschema/binding/ConstraintLetExpression.java

[ERROR] Cannot load ruleset pmd/category/java/custom.xml: Cannot resolve rule/ruleset reference 'pmd/category/java/custom.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/typeinfo/AbstractNamedModelInstanceTypeInfo.java

[ERROR] Cannot load ruleset pmd/category/java/custom.xml: Cannot resolve rule/ruleset reference 'pmd/category/java/custom.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

  • 55 others

Comment @coderabbitai help to get the list of available commands and usage tips.

@david-waltermire david-waltermire merged commit cf6331f into metaschema-framework:develop Dec 31, 2025
6 checks passed
@david-waltermire david-waltermire deleted the feature/604-choice-required branch December 31, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code generator: isRequired() doesn't account for fields inside choice blocks

1 participant