Enable export operation to have own schema#1566
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements support for an optional export.schema override in resource manifests, allowing resources to validate export input using a different schema than get/set/test (including a noFiltering mode), and adds test resources + Pester coverage to validate wildcard filtering scenarios (Issue #1232).
Changes:
- Extend the resource manifest model to allow
export.schemawithcommand,embedded, ornoFiltering. - Update export invocation to validate export input against the export-specific schema (or discard input for
noFiltering). - Add
dsctestfixtures/resources and a new Pester test to validate command/embedded/noFiltering export schema behaviors.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/dsctest/src/main.rs | Wires up a new export-schema subcommand and exposes schemas used by the new test resources. |
| tools/dsctest/src/export_schema.rs | Adds a test implementation that exercises export filtering with wildcard-capable input. |
| tools/dsctest/src/args.rs | Adds CLI surface for export-schema and schema generation for export/get vs export input schemas. |
| tools/dsctest/dsctest.dsc.manifests.json | Adds three new test resources covering export schema via command, embedded schema, and noFiltering. |
| tools/dsctest/Cargo.toml | Adds regex dependency for wildcard filtering in the test helper. |
| lib/dsc-lib/src/dscresources/resource_manifest.rs | Introduces ExportSchemaKind and adds schema to the manifest export operation model. |
| lib/dsc-lib/src/dscresources/command_resource.rs | Implements export-specific schema resolution and export-input validation / noFiltering behavior. |
| lib/dsc-lib-jsonschema/.versions.json | Bumps jsonschema patch version metadata (V3_2_2). |
| dsc/tests/dsc_resource_export.tests.ps1 | Adds Pester tests validating export input behavior across the new test resources. |
| Cargo.lock | Locks the new regex dependency for dsctest. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
821fc98 to
4015602
Compare
| if export.schema.is_none() && manifest.validate.is_some() { | ||
| let result = invoke_validate(resource, input, target_resource)?; | ||
| if result.valid { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let reason = result | ||
| .reason | ||
| .map(|s| s.trim().to_string()) | ||
| .filter(|s| !s.is_empty()) | ||
| .unwrap_or_else(|| t!("dscresources.commandResource.resourceInvalidJson").to_string()); | ||
| return Err(DscError::Validation(reason)); | ||
| } |
There was a problem hiding this comment.
can this be folded into the match block on line 642, since it's also going to check if export.schema.is_none()?
| } | ||
| } | ||
|
|
||
| fn verify_with_export_schema(input: &str, resource: &DscResource, target_resource: Option<&DscResource>) -> Result<(), DscError> { |
There was a problem hiding this comment.
Rather than pulling this every time we need to export, does it make more sense to add a field to DscResource like export_schema: Option<Map<String, Value>> where Some(_) is populated when export.schema is embedded/command and None when export.schema is "noFiltering"?
| _ => { | ||
| get_schema(resource, target_resource)? | ||
| } |
There was a problem hiding this comment.
If I'm understanding correctly, this causes export.schema: noFiltering to validate the instance properties with the instance schema instead of forbidding properties from being anything but an empty object?
I would expect that a manifest which explicitly forbids filtering to error when I pass a filtering property bag.
PR Summary
Enables resources supporting
exportto optionally have separate schema fromget,set, andtest.In the resource manifest under the
exportoperation, there is now an optionalschemaproperty that can be:command- same as normal schema which runs a command that returns JSON schemaembedded- same as normal schema which has embedded JSON schemanoFiltering- this string value indicates that the resource doesn't support filtering, so any user input is discarded before calling the resourceNew test resource added to validate these scenarios particularly where the
nameproperty is an enum, but theexportallowsnameto be an arbitrary string to allow passing in wildcards.PR Context
Fix #1232