-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add json-schemas for Configuration json files #2532
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4d7e6de
added json-schema for config/dns.json
psyirius 26256e1
[build-script]: strip $schema from config jsons before embedding
psyirius 5a60625
added json-schema for config/themes.json
psyirius 483baea
json-schema for config/themes.json required fields
psyirius 6fedea1
added json-schema for config/tweaks.json
psyirius c61b1e8
added json-schema for config/preset.json
psyirius 5e2acad
added json-schema for config/feature.json
psyirius 8844b85
json-schema adjustments
psyirius e2a870f
added json-schema for config/applications.json
psyirius e7d0637
Merge branch 'main' into config-schema
psyirius 632f295
Merge branch 'main' into config-schema
psyirius 14efc4f
Merge branch 'main' into config-schema
psyirius b9b617e
Merge branch 'main' into config-schema
psyirius 77e5c25
Merge branch 'main' into config-schema
psyirius 50cb1be
Merge branch 'main' into config-schema
psyirius 31ec62f
Merge branch 'main' into config-schema
ChrisTitusTech be9fae1
Update configs.Tests.ps1
ChrisTitusTech 01f4198
Update configs.Tests.ps1
ChrisTitusTech 97bf952
Update configs.Tests.ps1
ChrisTitusTech e6dbc81
Update configs.Tests.ps1
ChrisTitusTech 26a2b3d
Update configs.Tests.ps1
ChrisTitusTech c79fa58
Update configs.Tests.ps1
ChrisTitusTech bf56639
Update configs.Tests.ps1
ChrisTitusTech 4452177
Update configs.Tests.ps1
ChrisTitusTech 6616437
Update configs.Tests.ps1
ChrisTitusTech 5d53b96
Update configs.Tests.ps1
ChrisTitusTech 0d9b6f3
Update configs.Tests.ps1
ChrisTitusTech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"$schema": "../schemas/config/dns.json", | ||
"Google":{ | ||
"Primary": "8.8.8.8", | ||
"Secondary": "8.8.4.4", | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"$schema": "../schemas/config/preset.json", | ||
"Standard": [ | ||
"WPFTweaksAH", | ||
"WPFTweaksConsumerFeatures", | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,146 @@ | ||
# Import Config Files | ||
$global:importedconfigs = @{} | ||
Get-ChildItem .\config | Where-Object {$_.Extension -eq ".json"} | ForEach-Object { | ||
$global:importedconfigs[$psitem.BaseName] = Get-Content $psitem.FullName | ConvertFrom-Json | ||
} | ||
# Enable verbose output | ||
$VerbosePreference = "Continue" | ||
|
||
# Define Test-Schema function | ||
function Test-Schema { | ||
param ( | ||
$Object, | ||
$Schema | ||
) | ||
|
||
#=========================================================================== | ||
# Tests - Application Installs | ||
#=========================================================================== | ||
$errors = @() | ||
|
||
Describe "Config Files" -ForEach @( | ||
@{ | ||
name = "applications" | ||
config = $('{ | ||
"winget": "value", | ||
"choco": "value", | ||
"category": "value", | ||
"content": "value", | ||
"description": "value", | ||
"link": "value" | ||
}' | ConvertFrom-Json) | ||
}, | ||
@{ | ||
name = "tweaks" | ||
undo = $true | ||
} | ||
) { | ||
Context "$name config file" { | ||
It "Imports with no errors" { | ||
$global:importedconfigs.$name | should -Not -BeNullOrEmpty | ||
$Object.PSObject.Properties | ForEach-Object { | ||
$propName = $_.Name | ||
$propValue = $_.Value | ||
|
||
$propSchema = $Schema.Properties[$propName] | ||
if (-not $propSchema) { | ||
$errors += "Property '$propName' is not defined in the schema" | ||
return | ||
} | ||
if ($config) { | ||
It "Imports should be the correct structure" { | ||
$applications = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name | ||
$template = $config | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name | ||
$result = New-Object System.Collections.Generic.List[System.Object] | ||
Foreach ($application in $applications) { | ||
$compare = $global:importedconfigs.$name.$application | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name | ||
if ($(Compare-Object $compare $template) -ne $null) { | ||
$result.Add($application) | ||
} | ||
} | ||
|
||
$result | Select-String "WPF*" | should -BeNullOrEmpty | ||
switch ($propSchema.Type) { | ||
"String" { | ||
if ($propValue -isnot [string]) { | ||
$errors += "Property '$propName' should be a string but is $($propValue.GetType())" | ||
} | ||
} | ||
"Object" { | ||
if ($propValue -isnot [PSCustomObject]) { | ||
$errors += "Property '$propName' should be an object but is $($propValue.GetType())" | ||
} else { | ||
$errors += Test-Schema -Object $propValue -Schema $propSchema | ||
} | ||
} | ||
} | ||
if($undo) { | ||
It "Tweaks should contain original Value" { | ||
$tweaks = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name | ||
$result = New-Object System.Collections.Generic.List[System.Object] | ||
} | ||
|
||
foreach ($requiredProp in $Schema.Required) { | ||
if (-not $Object.PSObject.Properties.Name.Contains($requiredProp)) { | ||
$errors += "Required property '$requiredProp' is missing" | ||
} | ||
} | ||
|
||
foreach ($tweak in $tweaks) { | ||
$Originals = @( | ||
@{ | ||
name = "registry" | ||
value = "OriginalValue" | ||
}, | ||
@{ | ||
name = "service" | ||
value = "OriginalType" | ||
}, | ||
@{ | ||
name = "ScheduledTask" | ||
value = "OriginalState" | ||
return $errors | ||
} | ||
|
||
# Import Config Files | ||
$global:importedConfigs = @{} | ||
Get-ChildItem .\config -Filter *.json | ForEach-Object { | ||
try { | ||
$global:importedConfigs[$_.BaseName] = Get-Content $_.FullName | ConvertFrom-Json | ||
Write-Verbose "Successfully imported config file: $($_.FullName)" | ||
} catch { | ||
Write-Error "Failed to import config file: $($_.FullName). Error: $_" | ||
} | ||
} | ||
|
||
Describe "Config Files Validation" { | ||
BeforeAll { | ||
$script:configSchemas = @{ | ||
applications = @{ | ||
Type = "Object" | ||
Properties = @{ | ||
winget = @{ Type = "String" } | ||
choco = @{ Type = "String" } | ||
category = @{ Type = "String" } | ||
content = @{ Type = "String" } | ||
description = @{ Type = "String" } | ||
link = @{ Type = "String" } | ||
} | ||
Required = @("winget", "choco", "category", "content", "description", "link") | ||
} | ||
tweaks = @{ | ||
Type = "Object" | ||
Properties = @{ | ||
registry = @{ | ||
Type = "Object" | ||
Properties = @{ | ||
Path = @{ Type = "String" } | ||
Name = @{ Type = "String" } | ||
Type = @{ Type = "String" } | ||
Value = @{ Type = "String" } | ||
OriginalValue = @{ Type = "String" } | ||
} | ||
) | ||
Foreach ($original in $Originals) { | ||
$TotalCount = ($global:importedconfigs.$name.$tweak.$($original.name)).count | ||
$OriginalCount = ($global:importedconfigs.$name.$tweak.$($original.name).$($original.value) | Where-Object {$_}).count | ||
if($TotalCount -ne $OriginalCount) { | ||
$result.Add("$Tweak,$($original.name)") | ||
Required = @("Path", "Name", "Type", "Value", "OriginalValue") | ||
} | ||
service = @{ | ||
Type = "Object" | ||
Properties = @{ | ||
Name = @{ Type = "String" } | ||
StartupType = @{ Type = "String" } | ||
OriginalType = @{ Type = "String" } | ||
} | ||
Required = @("Name", "StartupType", "OriginalType") | ||
} | ||
ScheduledTask = @{ | ||
Type = "Object" | ||
Properties = @{ | ||
Name = @{ Type = "String" } | ||
State = @{ Type = "String" } | ||
OriginalState = @{ Type = "String" } | ||
} | ||
Required = @("Name", "State", "OriginalState") | ||
} | ||
} | ||
$result | Select-String "WPF*" | should -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
|
||
Context "Config File Structure" { | ||
It "Should import all config files without errors" { | ||
$global:importedConfigs | Should -Not -BeNullOrEmpty -Because "No config files were imported successfully" | ||
} | ||
|
||
It "Should have the correct structure for all configs" { | ||
$testSchemaScriptBlock = ${function:Test-Schema}.ToString() | ||
|
||
$results = $configSchemas.Keys | ForEach-Object -Parallel { | ||
$configName = $_ | ||
$importedConfigs = $using:global:importedConfigs | ||
$configSchemas = $using:configSchemas | ||
$config = $importedConfigs[$configName] | ||
$schema = $configSchemas[$configName] | ||
|
||
if (-not $config) { | ||
return "Config file '$configName' is missing or empty" | ||
} | ||
|
||
$testSchemaFunction = [ScriptBlock]::Create($using:testSchemaScriptBlock) | ||
& $testSchemaFunction -Object $config -Schema $schema | ||
} -ThrottleLimit 4 | ||
|
||
$results | Should -BeNullOrEmpty -Because "The following schema violations were found: $($results -join '; ')" | ||
} | ||
} | ||
} | ||
|
||
# Summarize test results | ||
$testResults = Invoke-Pester -PassThru | ||
if ($testResults.FailedCount -gt 0) { | ||
Write-Error "Tests failed. $($testResults.FailedCount) out of $($testResults.TotalCount) tests failed." | ||
exit 1 | ||
} else { | ||
Write-Output "All tests passed successfully!" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"definitions": { | ||
"url": { | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
}, | ||
"patternProperties": { | ||
"^[a-zA-Z_][a-zA-Z0-9_]*$": { | ||
"type": "object", | ||
"properties": { | ||
"content": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"category": { | ||
"type": "string", | ||
"enum": [ | ||
"Utilities", | ||
"Document", | ||
"Pro Tools", | ||
"Multimedia Tools", | ||
"Development", | ||
"Games", | ||
"Microsoft Tools", | ||
"Browsers", | ||
"Communications" | ||
] | ||
}, | ||
"choco": { | ||
"type": "string" | ||
}, | ||
"winget": { | ||
"type": "string" | ||
}, | ||
"link": { | ||
"$ref": "#/definitions/url" | ||
} | ||
}, | ||
"required": [ | ||
"content", | ||
"description", | ||
"category", | ||
"link", | ||
"choco", | ||
"winget" | ||
], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"patternProperties": { | ||
"^[a-zA-Z_][a-zA-Z0-9_]*$": { | ||
"type": "object", | ||
"properties": { | ||
"Primary": { | ||
"type": "string", | ||
"format": "ipv4" | ||
}, | ||
"Secondary": { | ||
"type": "string", | ||
"format": "ipv4" | ||
}, | ||
"Primary6": { | ||
"type": "string", | ||
"format": "ipv6" | ||
}, | ||
"Secondary6": { | ||
"type": "string", | ||
"format": "ipv6" | ||
} | ||
}, | ||
"required": ["Primary", "Secondary", "Primary6", "Secondary6"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@psyirius @ChrisTitusTech This code for handling special characters is not needed anymore, as we're dynamically generating the UI, therefore skipping the XAML Reader in the process, so I recommend removing it plus any comments related to it.