Skip to content

Commit 78ac043

Browse files
Misc fixes related to json schema validation
1 parent 950d0b2 commit 78ac043

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/dsc/psresourceget.ps1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ class PSResource {
8282
}
8383

8484
[string] ToJson() {
85-
return ($this | Select-Object -ExcludeProperty _inDesiredState | ConvertTo-Json -Compress)
85+
$retVal = ($this | Select-Object -ExcludeProperty _inDesiredState | ConvertTo-Json -Compress -EnumsAsStrings)
86+
Write-Trace -message "Serializing PSResource to JSON. Name: $($this.name), Version: $($this.version), Scope: $($this.scope), RepositoryName: $($this.repositoryName), PreRelease: $($this.preRelease), _exist: $($this._exist)" -level trace
87+
Write-Trace -message "Serialized JSON: $retVal" -level trace
88+
return $retVal
8689
}
8790

8891
[string] ToJsonForTest() {
89-
return ($this | ConvertTo-Json -Compress -Depth 5)
92+
return ($this | ConvertTo-Json -Compress -Depth 5 -EnumsAsStrings)
9093
}
9194
}
9295

@@ -140,12 +143,17 @@ class PSResourceList {
140143
$resourceJson = "[$resourceJson]"
141144
$jsonString = "{'repositoryName': '$($this.repositoryName)','resources': $resourceJson}"
142145
$jsonString = $jsonString -replace "'", '"'
143-
return $jsonString | ConvertFrom-Json | ConvertTo-Json -Compress
146+
$retVal = $jsonString | ConvertFrom-Json | ConvertTo-Json -Compress -EnumsAsStrings
147+
148+
Write-Trace -message "Serializing PSResourceList to JSON. RepositoryName: $($this.repositoryName), TrustedRepository: $($this.trustedRepository), Resources count: $($this.resources.Count)" -level trace
149+
Write-Trace -message "Serialized JSON: $retVal" -level trace
150+
151+
return $retVal
144152
}
145153

146154
[string] ToJsonForTest() {
147155
Write-Trace -message "Serializing PSResourceList to JSON for test output. RepositoryName: $($this.repositoryName), TrustedRepository: $($this.trustedRepository), Resources count: $($this.resources.Count)" -level trace
148-
$jsonForTest = $this | ConvertTo-Json -Compress -Depth 5
156+
$jsonForTest = $this | ConvertTo-Json -Compress -Depth 5 -EnumsAsStrings
149157
Write-Trace -message "Serialized JSON: $jsonForTest" -level trace
150158
return $jsonForTest
151159
}
@@ -162,6 +170,7 @@ class Repository {
162170
Repository([string]$name) {
163171
$this.name = $name
164172
$this._exist = $false
173+
$this.repositoryType = 'Unknown'
165174
}
166175

167176
Repository([string]$name, [string]$uri, [bool]$trusted, [int]$priority, [string]$repositoryType) {
@@ -185,10 +194,11 @@ class Repository {
185194
Repository([string]$name, [bool]$exist) {
186195
$this.name = $name
187196
$this._exist = $exist
197+
$this.repositoryType = 'Unknown'
188198
}
189199

190200
[string] ToJson() {
191-
return ($this | ConvertTo-Json -Compress)
201+
return ($this | ConvertTo-Json -Compress -EnumsAsStrings)
192202
}
193203
}
194204

src/dsc/psresourcelist.dsc.resource.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"repositoryName": {
9393
"title": "Repository Name",
9494
"description": "The name of the repository from where the resources are acquired.",
95-
"type": "string"
95+
"type": ["string", "null"]
9696
},
9797
"trustedRepository": {
9898
"title": "Trusted Repository",
@@ -115,7 +115,7 @@
115115
},
116116
"$defs": {
117117
"Scope": {
118-
"type": "string",
118+
"type": ["string", "null"],
119119
"title": "Scope",
120120
"description": "Scope of the resource installation.",
121121
"enum": [
@@ -133,12 +133,12 @@
133133
"name": {
134134
"title": "Name",
135135
"description": "The name of the resource.",
136-
"type": "string"
136+
"type": ["string", "null"]
137137
},
138138
"version": {
139139
"title": "Version",
140140
"description": "The version range of the resource.",
141-
"type": "string"
141+
"type": ["string", "null"]
142142
},
143143
"scope": {
144144
"title": "Scope",
@@ -148,7 +148,7 @@
148148
"repositoryName": {
149149
"title": "Repository Name",
150150
"description": "The name of the repository from where the resource is acquired.",
151-
"type": "string"
151+
"type": ["string", "null"]
152152
},
153153
"preRelease": {
154154
"title": "Pre-Release version",

src/dsc/repository.dsc.resource.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"uri": {
101101
"title": "URI",
102102
"description": "The URI of the repository.",
103-
"type": "string",
103+
"type": ["string", "null"],
104104
"format": "uri"
105105
},
106106
"trusted": {

0 commit comments

Comments
 (0)