feat: Map qualified, nullable and class-typed properties to correct JSON schema types - #5
Open
Gijsreyn wants to merge 3 commits into
Open
feat: Map qualified, nullable and class-typed properties to correct JSON schema types#5Gijsreyn wants to merge 3 commits into
Gijsreyn wants to merge 3 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adapted resource manifests generated from class-based resources that declare their property types the fully qualified way (
[System.Boolean],[System.Int32],[System.Nullable[T]]) silently fell back to"string", because the type map only knew the short aliases. Properties typed as a class from the same file andPSCredentialwere mapped to strings as well, and a[ValidateSet()]on an array or numeric property produced a top-level string enum. Consumers such as Microsoft365DSC and AzureDevOpsDsc worked around all of this with post-processing scripts.This change makes the tool produce the correct schema on its own.
Example
Given this resource:
the embedded schema before this change was:
{ "properties": { "Name": { "type": "string", "title": "Name", "description": "The Name property." }, "Enabled": { "type": "string", "title": "Enabled", "description": "The Enabled property." }, "Level": { "type": "string", "enum": ["0", "1", "2"], "title": "Level", "description": "The Level property." }, "Protocols": { "type": "string", "enum": ["Http", "Https"], "title": "Protocols", "description": "The Protocols property." }, "Credential": { "type": "string", "title": "Credential", "description": "The Credential property." }, "Segments": { "type": "array", "items": { "type": "string" }, "title": "Segments", "description": "The Segments property." } } }with
"capabilities": ["get", "set", "test", "export"], and after it is:{ "properties": { "Name": { "type": "string", "title": "Name", "description": "The unique name of the resource." }, "Enabled": { "type": "boolean", "title": "Enabled", "description": "Whether the resource is enabled." }, "Level": { "type": "integer", "enum": [0, 1, 2], "title": "Level", "description": "The scan level." }, "Protocols": { "type": "array", "items": { "type": "string", "enum": ["Http", "Https"] }, "title": "Protocols", "description": "The allowed protocols." }, "Credential": { "$ref": "#/$defs/PSCredential", "title": "Credential", "description": "The credential used to connect." }, "Segments": { "type": "array", "items": { "$ref": "#/$defs/Segment" }, "title": "Segments", "description": "All segments." } }, "$defs": { "PSCredential": { "type": "object", "properties": { "username": { "type": "string" }, "password": { "type": "string" } } }, "Segment": { "type": "object", "additionalProperties": false, "properties": { "Name": { "type": "string", "title": "Name", "description": "The segment name." }, "AllowedOrigins": { "type": "array", "items": { "type": "string" }, "title": "AllowedOrigins", "description": "The allowed origins." } } } } }with
"capabilities": ["get", "set", "test"], because the adapter invokesExporton the type and an instanceExport()can never run.Generating from source files
A module that keeps one source file per resource can now name the manifests after the built module without post-processing:
Every manifest carries
"type": "MyModule/<Class>","path": "MyModule.psd1"and the version and author ofMyModule.psd1. A four-partModuleVersionsuch as1.26.1007.1is written as1.26.1007, because the manifest requires a semantic version.Changes
Nullable[T], generic collections and additional CLR types (Guid,TimeSpan,SecureString, unsigned integers, ...) map to their JSON schema types.$defsand referenced with$ref, including arrays of a class and nested classes. A class without[DscProperty()]members is described by its public instance properties.PSCredentialreferences a shared definition withusernameandpassword, the shape the PowerShell adapter turns into a credential.[ValidateSet()]values go underitemsfor arrays and are converted to the mapped type for numeric and boolean properties.[System.ComponentModel.Description()]attributes when the comment-based help has no entry.-ModuleManifestPathonNew-DscAdaptedResourceManifest; four-part versions are truncated toMajor.Minor.Build.exportis only advertised for astatic Export().$schemais the canonicalhttps://aka.ms/dsc/schemas/v3/bundled/resource/adapted/manifest.json; DSC 3.3 reports the old URI as deprecated.ConvertTo-DscPropertyOverrideFromConfigis public so the tasks can applyPropertyOverridesfrombuild.yaml.Index was out of rangeon class instantiation under 5.1, sobuild.yamlsetsCodeCoverage.UseBreakpoints: true.mainfails the same way today.Verification
dsc resource listanddsc resource schemaon dsc 3.3.0-preview.4 return them with their$defsand no deprecation warning.boolean,integer,$defs/SqlReason,$defs/DatabasePermissionand$defs/PSCredential.This change is