Repository navigation
Replace PowerShell adapter validation with embedded resource schemas - #1775
Steve Lee (SteveL-MSFT) wants to merge 9 commits into
Conversation
Remove the no-op validate operation, emit schemas for discovered resources, and preserve legacy adapter behavior. Update schema fixtures, cache versions, documentation, and regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
5 open issues
When$schema.typeincludes'null'(for example@('string','null')), addinganyOfwithout a… · New RaisingConvertTo-Jsondepth to 100 can significantly increase serialization time and output… · New This performs a linear scan over$AllTypeDefinitionsfor every DSC property. If a module has many… · New This line looks like it is intended to be part of the markdown table, but it no longer starts with… · New$isKeyPropertyis now set for bothKeyandMandatory, but the name implies it tracks only key… · New
What changed in this PR
Updates the PowerShell/Windows PowerShell DSC adapters to remove the standalone validate operation and instead provide embedded JSON schemas for resources, updating cache schema versions and docs accordingly.
Changes:
- Removed
validateoperation wiring from adapter manifests and the adapter entry script. - Added embedded schema generation for discovered resources (including enum/ValidateSet handling) and increased cache schema versions.
- Added Pester tests to validate embedded schemas and ensure the removed
Validateoperation is rejected.
| File | Description |
|---|---|
| docs/reference/resources/Microsoft/Windows/WindowsPowerShell/index.md | Updates documented cache schema version for Windows PowerShell adapter. |
| docs/reference/resources/Microsoft/DSC/PowerShell/index.md | Updates documented cache schema version for PowerShell adapter. |
| docs/reference/resources/Microsoft/Adapter/WindowsPowerShell/index.md | Updates cache schema version and clarifies schema-based validation behavior. |
| docs/reference/resources/Microsoft/Adapter/PowerShell/index.md | Updates cache schema version and clarifies schema-based validation behavior. |
| adapters/powershell/windowspowershell.dsc.resource.json | Replaces validate operation with embedded schema in resource manifest. |
| adapters/powershell/powershell.dsc.resource.json | Replaces validate operation with embedded schema in resource manifest. |
| adapters/powershell/WindowsPowerShell_adapter.dsc.resource.json | Removes validate and adds minimal embedded schema to adapter manifest. |
| adapters/powershell/PowerShell_adapter.dsc.resource.json | Removes validate and adds minimal embedded schema to adapter manifest. |
| adapters/powershell/psDscAdapter/win_psDscAdapter.psm1 | Bumps cache schema version and adds enum/ValidateSet value discovery. |
| adapters/powershell/psDscAdapter/psDscAdapter.psm1 | Bumps cache schema version and adds enum/ValidateSet value discovery. |
| adapters/powershell/psDscAdapter/powershell.resource.ps1 | Removes Validate op, generates per-resource JSON schema, and emits deeper JSON. |
| adapters/powershell/Tests/schema.tests.ps1 | Adds tests validating embedded schemas and removed Validate behavior. |
| adapters/powershell/Tests/powershellgroup.resource.tests.ps1 | Extends existing tests to assert schema presence/shape. |
| adapters/powershell/Tests/PSAdaptedTestClassResource.dsc.adaptedResource.json | Adjusts adapted resource schema structure. |
| adapters/powershell/Tests/PSAdapted.tests.ps1 | Adds tests ensuring adapted resource schema rejects invalid inputs. |
Review effort: Lite
Resolve the adapter entry-point conflict by retaining upstream process blocks and named parameters while keeping schema-based validation and the removed Validate operation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve null values in nullable validation sets, restrict deeper JSON serialization to listings, and reuse indexed type definitions for enum and inheritance lookups. Clarify required-property naming and add nullable, array, and inherited-enum regressions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Code Coverage ReportNo Rust files were changed in this PR. 🔵 Full Codebase Coverage83% (good)
|
|
Steve Lee (@SteveL-MSFT) - are any doc updates needed with this change? |
Add schema retrieval examples, document validation-set and null behavior, and distinguish legacy wrapper validation from per-resource schemas and cached metadata. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Great question. Added doc update. |
Mikey Lombardi (He/Him) (michaeltlombardi)
left a comment
There was a problem hiding this comment.
A few high-level thoughts:
-
I think we should probably move the schema generation into the discovery/caching instead of reconstructing on every invocation.
-
The current generation is attribute-unaware, so it can't do useful things like pull the pattern from
ValidatePatterninto the property definition as thepatternkeyword or determine whether the property should accept explicitnullvalues. -
I pulled the changes locally to verify and noticed that the generated schema for class-based resources completely failed to retrieve schemas for nested classes. It seems to work for enums though.
-
There's no way in the current implementation for a resource author to specify their own schema in the type definition. They either have to maintain the schema by hand in an adapted manifest or let this implementation generate the schema for the resource entirely.
-
We're squashing a lot of type schemas to their simplest representation, which I think is okay for this PR, but could be usefully enhanced. For example, we could generate the minimum and maximum bounds for numeric properties with
([type]$propertyType)::<Min|Max>Valueor define theformatkeyword with a standard defined format where coherent, like:--- # datetime type: string format: date-time --- # uri type: string format: uri
With access to the resource property attributes we can do even more, like pull
ValidatePatterninto thepatternkeyword,ValidateLengthinto theminLengthandmaxLengthkeywords, and so on. -
There are some thorny issues for retrieving data for properties as nested classes, but I think we can resolve most or all of them - but not cheaply, which reinforces the benefit of caching the schema generation during discovery.
-
There seems to be some miswiring going on, because while invoking the resource script directly does emit the resource schema, that value remains null in the output data from
dsc resource list, at least for me.dsc resource list --adapter *PowerShell* | ConvertFrom-Json | Select-Object -Property type, schema
Canonicalize schema and single-resource output property names, use standard required lists, and derive nullability from explicit metadata. Refresh adapter caches and update regressions and reference examples. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use canonical input names in discovery and Windows cache tests, assert successful lookup-table invocations, and isolate a MOF-compatible Windows schema fixture while retaining modern punctuation-name coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep nullable module-defined enums in modern adapter coverage, but use ordinary enums for Windows PowerShell discovery. Run compatible fixture schema assertions on every platform and retain Windows-only script resource checks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Steve Lee (@SteveL-MSFT) - Thanks for working through the earlier rounds; the canonical names and the plain
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>



The PowerShell adapters currently advertise a
validateoperation that always reports success, bypassing meaningful input validation. Replace it with embedded resource schemas so DSC validates adapted inputs before invoking PowerShell.Breaking change and migration
Resource property names are now case-sensitive canonical camelCase names, including key, mandatory, and optional properties. Existing configurations using
Name,Ensure, or other PowerShell casing must migrate to the exact spelling reported bydsc resource schema -r '<moduleName>/<resourceName>'. Schemas useadditionalProperties: false, so incorrectly cased optional names cannot bypass validation.Single-resource get/set/test/export output uses the same canonical names and omits unset optional null properties unless explicitly nullable. Case-sensitive output consumers must migrate too. Deprecated full-configuration wrapper output is unchanged. The changelog and adapter reference pages describe these changes.
Changes
validatefrom all four adapter manifests and generate embedded schemas for discovered class-based and MOF-based resources.ValidateSet(..., IgnoreCase = $false)._inDesiredStatefor test output. Let DSC omit_metadatainjection when the closed resource schema rejects it.External enums and custom representations not resolved from metadata remain validated by PowerShell. Nested member constraints are not inferred yet.
Validation
187 PowerShell/Pester tests passed, with 3 existing skips, through repository-root
build.ps1 -SkipBuild -Test -ExcludeRustTests. This covered schema, adapted manifests, adapter config/resource operations, and DSC discovery using the prior successful PR CI macOS binaries with the updated adapter files. No Rust code changed. Windows PowerShell runtime verification remains in CI; local coverage includes the Windows AST metadata reader and MOF-shaped metadata.Follow-ups