PowerShell / PowerShell/DSC

Resource and Canonical Properties use of null

Open
#1,237 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Need-Review
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Summary

There are built-in resources and canonical properties (_inDesiredState) that use null in addition to actual type of the property. Null should NOT be a valid type unless the property actually accepts null as a valid use case. By allowing null it can confuse users when we have auto-complete in BICEP and weakens the strongly validated schema.

JSON schema null and undefined properties are different.

https://json-schema.org/understanding-json-schema/reference/null

Excerpt:

It's important to remember that in JSON, null isn't equivalent to something being absent. See Required Properties for an example.

The mechanism to indicate a property is required or optional is by the use of the required property.

I understand that we're using nullable types so we can return only the properties that are actually defined instead of empty strings or false bools but it is not best practice.

Resources with Nullable Properties:

  1. Microsoft.DSC.Debug/Echo
    showSecrets: type: ["boolean", "null"]

  2. Microsoft.DSC.Transitional/PowerShellScript
    getScript: type: ["string", "null"]
    setScript: type: ["string", "null"]
    testScript: type: ["string", "null"]
    input: type: ["string", "boolean", "integer", "object", "array", "null"]
    output: type: ["array", "null"]
    _inDesiredState: type: ["boolean", "null"]

  3. Microsoft.DSC.Transitional/WindowsPowerShellScript
    getScript: type: ["string", "null"]
    setScript: type: ["string", "null"]
    testScript: type: ["string", "null"]
    input: type: ["string", "boolean", "integer", "object", "array", "null"]
    output: type: ["array", "null"]
    _inDesiredState: type: ["boolean", "null"]

  4. Microsoft.OpenSSH.SSHD/Windows
    shell: type: ["string", "null"]
    cmdOption: type: ["string", "null"]
    escapeArguments: type: ["boolean", "null"]

  5. Microsoft.Windows/RebootPending
    reasons: type: ["array", "null"]
    The entire object itself: type: ["object", "null"]

  6. Microsoft.Windows/Registry
    _metadata: anyOf: [{"$ref": "#/$defs/Metadata"}, {"type": "null"}]
    valueName: type: ["string", "null"]
    valueData: anyOf: [{"$ref": "#/$defs/RegistryValueData"}, {"type": "null"}]
    _exist: type: ["boolean", "null"]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the JSON schemas for the listed DSC resources and the canonical _inDesiredState property, using the issue's resource and property list as the scope. Check which properties genuinely accept null versus merely being optional, then validate the resulting schemas against the documented JSON Schema semantics and Bicep autocomplete expectations. Done means removing unjustified null types while preserving legitimate nullable values.

Written by the indexing model from the issue text.

Assessment

Tech stack
json
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.