Unique members in an array using YAML
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 474
- Forks
- 65
- Avg merge
- 22h 25m
- Merged PRs (30d)
- 26
Description
Investigate support for using functions for this case. See discussion for details.
Discussed in https://github.com/microsoft/PSRule/discussions/2787
Originally posted by sapritchard March 3, 2025
Hi, I'm looking to see if I can iterate over an array to ensure the members are unique using a YAML rule file. I can achieve the result using PowerShell but would like to understand where I am going wrong using YAML. My PowerShell version of the rule is:
Rule 'Unique Members' {
$array_members = @($TargetObject.Type.datacenter.Name)
$Assert.Subset($TargetObject, 'Type.datacenter.Name', $array_members, $null, $True)
}
I've tried a few variations with a YAML rule, I think the below is close:
---
# Synopsis: Each member of the Name array is unique
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
metadata:
name: datacenter.Name.member.unique
spec:
condition:
field: Type.datacenter.Name
subset:
- .
unique: true
My configuration is in JSON:
{
"Type": {
"datacenter": {
"Name": [
"DEV_LAB",
"DEV_LAB1"
]
}
}
}
My result:
FAIL datacenter.Name.member.unique
Each member of the Name array is unique
File: datacenter.json:2:8
Reason:
- Path Type.datacenter.Name: The field 'Type.datacenter.Name' did not contain '.'.
Again I'm sure it's just me not interpreting the documentation correctly. Appreciate any help.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read discussion #2787 and compare the YAML rule condition with the shown PowerShell rule. Determine whether YAML can express the requested unique-members check; done should be a decided support path or a clearly documented limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, yaml
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100