Skip to content

feat: add list-allowed-values command and visitor#666

Open
david-waltermire wants to merge 2 commits intometaschema-framework:developfrom
david-waltermire:feature/list-allowed-values
Open

feat: add list-allowed-values command and visitor#666
david-waltermire wants to merge 2 commits intometaschema-framework:developfrom
david-waltermire:feature/list-allowed-values

Conversation

@david-waltermire
Copy link
Contributor

@david-waltermire david-waltermire commented Feb 16, 2026

Summary

  • Migrate AllowedValueCollectingNodeItemVisitor from liboscal-java to core module at dev.metaschema.core.metapath.item.node, making it available to all Metaschema users
  • Add list-allowed-values CLI command that generates a YAML listing of allowed-values constraints for any Metaschema module
  • Register the new command in MetaschemaCommands and the module-info service provider

Motivation

The visitor and command were previously in liboscal-java and oscal-cli respectively, but contain zero OSCAL-specific logic. All imports are dev.metaschema.core.* types. Moving them to metaschema-java makes this functionality available to all Metaschema-based projects.

Changes

File Change
core/.../AllowedValueCollectingNodeItemVisitor.java New - visitor migrated from liboscal-java with Javadoc added
core/.../AllowedValueCollectingNodeItemVisitorTest.java New - 3 tests using mock model builder infrastructure
metaschema-cli/.../ListAllowedValuesCommand.java New - CLI command following GenerateDiagramCommand pattern
metaschema-cli/.../MetaschemaCommands.java Register new command
metaschema-cli/module-info.java Add requires for Jackson YAML and provides entry
metaschema-cli/.../CLITest.java Add help and execution test cases

Test plan

  • AllowedValueCollectingNodeItemVisitorTest - 3 tests (finds constraints, empty for no constraints, handles multiple)
  • CLITest - list-allowed-values --help returns OK
  • CLITest - list-allowed-values <module> returns OK with YAML output
  • Full CI build: mvn clean install -PCI -Prelease passes
  • Manual CLI verification: correct YAML output for test module

Summary by CodeRabbit

  • New Features

    • Added "list-allowed-values" CLI command to produce YAML reports of allowed-values constraints (locations, targets, values).
    • Introduced a module-level mechanism to collect and organize allowed-values constraints for downstream reporting.
  • Tests

    • Added unit tests validating the collector and CLI output (help, usage, and YAML generation).

Migrate AllowedValueCollectingNodeItemVisitor from liboscal-java to the
core module, making it available to all Metaschema users. The visitor
traverses a module's node items to collect allowed-values constraints
organized by target node.

Add a new list-allowed-values CLI command that generates a YAML listing
of all allowed-values constraints for a given Metaschema module. This
command was previously only available in oscal-cli with OSCAL-specific
module loading hardcoded; the generic version accepts any Metaschema
module via a positional argument.
@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds a visitor that collects allowed-values constraints from Metaschema modules and a CLI command that emits those collected constraints as structured YAML; includes tests and module descriptor updates.

Changes

Cohort / File(s) Summary
Visitor Implementation
core/src/main/java/dev/metaschema/core/metapath/item/node/AllowedValueCollectingNodeItemVisitor.java
New public visitor class that traverses module node items (flags, fields, assemblies), applies Let-bindings to build DynamicContext, evaluates allowed-values targets, and aggregates results into NodeItemRecord and AllowedValuesRecord collections accessible via getAllowedValueLocations().
Visitor Tests
core/src/test/java/dev/metaschema/core/metapath/item/node/AllowedValueCollectingNodeItemVisitorTest.java
New test suite covering discovery of allowed-values constraints, absence of constraints, and multiple-constraint scenarios using mocked module builders.
CLI Command
metaschema-cli/src/main/java/dev/metaschema/cli/commands/ListAllowedValuesCommand.java
New terminal command list-allowed-values that loads a module, invokes the visitor to collect constraints, and emits a YAML report grouped by target definition; supports stdout or file output and includes error handling for IO and argument issues.
CLI Registry & Module Descriptor
metaschema-cli/src/main/java/dev/metaschema/cli/commands/MetaschemaCommands.java, metaschema-cli/src/main/java/module-info.java
Registers the new ListAllowedValuesCommand in the command registry and adds com.fasterxml.jackson.dataformat.yaml to module requirements; exposes the new command in the module provides block.
CLI Tests
metaschema-cli/src/test/java/dev/metaschema/cli/CLITest.java
Adds CLI test invocations for list-allowed-values --help and execution that writes YAML output; includes assertion of generated YAML content.

Sequence Diagram

sequenceDiagram
    participant User as User/CLI
    participant Cmd as ListAllowedValuesCommand
    participant Loader as Module Loader
    participant Visitor as AllowedValueCollectingNodeItemVisitor
    participant Module as IModule
    participant YAML as YAML Generator
    participant Output as File/Stdout

    User->>Cmd: list-allowed-values module.xml [output.yaml]
    Cmd->>Loader: resolve & load module
    Loader->>Module: parse module
    Cmd->>Visitor: create visitor with context
    Cmd->>Visitor: visit(module)
    Visitor->>Module: traverse node items (flags/fields/assemblies)
    Visitor->>Visitor: apply Let-bindings, evaluate targets
    Visitor->>Visitor: collect AllowedValuesRecords into NodeItemRecords
    Visitor-->>Cmd: return collected records
    Cmd->>YAML: generate structured YAML grouped by target
    YAML->>Output: write to file or stdout
    Output-->>User: display/save results
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Poem

🐰 I hop through schemas, sniffing each rule,
Gathering values from field, flag, and tool,
I bind all the Lets and follow each trail,
Spit out some YAML — happy tails prevail! 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.48% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main changes: adding a list-allowed-values command and a visitor component for extracting allowed-values constraints from Metaschema modules.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.21.0)
metaschema-cli/src/test/java/dev/metaschema/cli/CLITest.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.


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

Verify the YAML output contains expected constraint locations, types,
target paths, allowed values, and allow-other settings by writing to a
file and checking the content.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
core/src/main/java/dev/metaschema/core/metapath/item/node/AllowedValueCollectingNodeItemVisitor.java (1)

188-196: Consider returning an unmodifiable list from getAllowedValues.
This prevents external mutation of the internal collection while preserving the addAllowedValues API.

♻️ Suggested change
 import java.util.Collection;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@
   `@NonNull`
   public List<AllowedValuesRecord> getAllowedValues() {
-    return allowedValues;
+    return Collections.unmodifiableList(allowedValues);
   }

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.

1 participant