feat: add list-allowed-values command and visitor#666
feat: add list-allowed-values command and visitor#666david-waltermire wants to merge 2 commits intometaschema-framework:developfrom
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds 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
Sequence DiagramsequenceDiagram
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
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~55 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/src/main/java/dev/metaschema/core/metapath/item/node/AllowedValueCollectingNodeItemVisitor.java (1)
188-196: Consider returning an unmodifiable list fromgetAllowedValues.
This prevents external mutation of the internal collection while preserving theaddAllowedValuesAPI.♻️ 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); }
Summary
AllowedValueCollectingNodeItemVisitorfrom liboscal-java tocoremodule atdev.metaschema.core.metapath.item.node, making it available to all Metaschema userslist-allowed-valuesCLI command that generates a YAML listing of allowed-values constraints for any Metaschema moduleMetaschemaCommandsand the module-info service providerMotivation
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
core/.../AllowedValueCollectingNodeItemVisitor.javacore/.../AllowedValueCollectingNodeItemVisitorTest.javametaschema-cli/.../ListAllowedValuesCommand.javaGenerateDiagramCommandpatternmetaschema-cli/.../MetaschemaCommands.javametaschema-cli/module-info.javarequiresfor Jackson YAML andprovidesentrymetaschema-cli/.../CLITest.javaTest plan
AllowedValueCollectingNodeItemVisitorTest- 3 tests (finds constraints, empty for no constraints, handles multiple)CLITest-list-allowed-values --helpreturns OKCLITest-list-allowed-values <module>returns OK with YAML outputmvn clean install -PCI -PreleasepassesSummary by CodeRabbit
New Features
Tests