Skip to content

[Test-ObjectGraph] When the schema specifies that a parameter is required and another parameter is not correct, that other parameter is not listed as failed. #129

@ykuijs

Description

@ykuijs

When the schema specifies that a parameter is required and another parameter is not correct (incorrect type or using parameter that is unknown), those other parameters are not listed as failed.

Reproduction:

  • DefaultLength is specified as string, but the schema expects and int.
  • The property DoesNotExist is not specified in the schema.
$data = @{
    NonNodeData = @{
        AzureAD = @{
            AuthenticationMethodPolicy = @(
                @{
                    DefaultLength = 'string'
                    DoesNotExist = 'string'
                    DefaultLifetimeInMinutes = 10
                }
            )
        }
    }
}

$schema = @{
    NonNodeData = @{
        '@Type' = 'PSMapNode'
        AzureAD = @{
            '@Type' = 'PSMapNode'
            AuthenticationMethodPolicy = @(
                @{
                    '@Type' = 'PSMapNode'
                    DefaultLength = @{ '@Type' = 'Int' }
                    DefaultLifetimeInMinutes = @{ '@Type' = 'Int' }
                    Ensure = @{ '@Type' = 'String' }
                    Id = @{ '@Type' = 'String'; '@Required' = $true }
                    IncludeTargets = @(
                        @{
                            '@Type' = 'PSMapNode'
                            Id = @{ '@Type' = 'String' }
                            TargetType = @{ '@Type' = 'String' }
                        }
                    )
                    IsUsableOnce = @{ '@Type' = 'Bool' }
                    MaximumLifetimeInMinutes = @{ '@Type' = 'Int' }
                    MinimumLifetimeInMinutes = @{ '@Type' = 'Int' }
                    State = @{ '@Type' = 'String' }
                }
            )
        }
    }
}

$result = $data | Test-Object $schema
$result

Output:

Path                                              Value                                    Valid Issue
----                                              -----                                    ----- -----
NonNodeData.AzureAD.AuthenticationMethodPolicy[0] @{DefaultLeng…='string';DefaultLife…=10}  [X]  The required node condition 'Id' is not met
NonNodeData.AzureAD.AuthenticationMethodPolicy    @(@{DefaultLeng…=…;…})                    [X]  The following nodes are not accepted: 0
NonNodeData.AzureAD                               @{Authenticat…=@(…)}                      [X]  The following nodes are not accepted: Authenticat…
NonNodeData                                       @{AzureAD=@{Authenticat…=…}}              [X]  The following nodes are not accepted: AzureAD
                                                  @{NonNodeData=@{AzureAD=…}}               [X]  The following nodes are not accepted: NonNodeData

The incorrect type of the DefaultLength parameter and the fact that the DoesNotExist parameter is unknown are missing in the list. I would have expected that the code would output all discovered issues.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions