@@ -296,6 +296,14 @@ class schemaDocument {
296
296
}
297
297
}
298
298
}
299
+ class schemaDefinition {
300
+ [ValidateSet (' object' )]
301
+ [string ]$type = ' object'
302
+ [object ]$properties
303
+ [string []]$required
304
+
305
+ schemaDefinition () {}
306
+ }
299
307
$Global :RawSchema = $null ;
300
308
function Get-Document {
301
309
[CmdletBinding (
@@ -362,6 +370,35 @@ function Get-Definition {
362
370
}
363
371
}
364
372
}
373
+ function ConvertTo-Definition {
374
+ [CmdletBinding (
375
+ HelpURI = ' https://github.com/SchemaModule/PowerShell/blob/master/docs/ConvertTo-SchemaDefinition.md#convertto-schemadefinition' ,
376
+ PositionalBinding = $true )]
377
+ # [OutputType([string],[schemaDefinition])]
378
+ param (
379
+ [Parameter (ValueFromPipeline )]
380
+ [object ]$Definition ,
381
+ [switch ]$AsJson
382
+ )
383
+ process {
384
+ Write-Verbose " Creating New Definition" ;
385
+ $NewDefinition = New-SchemaElement - Type definition;
386
+ $NewDefinition.required = $Definition.required ;
387
+ $NewDefinition.properties = $Definition.properties ;
388
+ foreach ($defProperty in $Definition.properties.psobject.properties.name ) {
389
+ write-verbose " Definition Property : $ ( $defProperty ) "
390
+ if ($NewDefinition.properties .($defProperty ).type) {
391
+ write-verbose " Found type property"
392
+ $NewDefinition.properties .($defProperty ).type = $Definition.properties .($defProperty ).type.split(' ' )[0 ]
393
+ }
394
+ }
395
+ if ($AsJson ) {
396
+ return ($NewDefinition | ConvertTo-Json - Depth 99 )
397
+ } else {
398
+ return $NewDefinition
399
+ }
400
+ }
401
+ }
365
402
function Get-Reference {
366
403
[CmdletBinding (
367
404
HelpURI = ' https://github.com/SchemaModule/PowerShell/blob/master/docs/Get-SchemaReference.md#get-schemareference' ,
@@ -557,7 +594,7 @@ function New-Property {
557
594
[ValidateNotNullOrEmpty ()]
558
595
[string ]$Name ,
559
596
560
- [ValidateSet ([schemaDocument ], [schemaNumber ], [schemaInteger ], [schemaString ], [schemaObject ], [schemaArray ], [schemaBoolean ])]
597
+ [ValidateSet ([schemaDocument ], [schemaNumber ], [schemaInteger ], [schemaString ], [schemaObject ], [schemaArray ], [schemaBoolean ], [ schemaDefinition ] )]
561
598
$Value ,
562
599
563
600
$Array
@@ -578,7 +615,7 @@ function New-Element {
578
615
PositionalBinding = $true )]
579
616
[OutputType ([schemaDocument ], [schemaString ], [schemaInteger ], [schemaNumber ], [schemaBoolean ], [schemaObject ], [schemaArray ])]
580
617
param (
581
- [ValidateSet (' string' , ' number' , ' integer' , ' object' , ' boolean' , ' array' , ' document' )]
618
+ [ValidateSet (' string' , ' number' , ' integer' , ' object' , ' boolean' , ' array' , ' document' , ' definition ' )]
582
619
[string ]$Type
583
620
)
584
621
if ($PSCmdlet.ShouldProcess (" NewElement" )) {
@@ -605,6 +642,9 @@ function New-Element {
605
642
' document' {
606
643
[schemaDocument ]::new()
607
644
}
645
+ ' definition' {
646
+ [schemaDefinition ]::new()
647
+ }
608
648
}
609
649
}
610
650
}
@@ -834,6 +874,14 @@ function ConvertTo-Element {
834
874
write-verbose " Found `$ schema property"
835
875
$Result.schema = $Object .$prop
836
876
}
877
+ elseif ($prop -eq ' definitions' ) {
878
+ write-verbose " Found Definitions"
879
+ write-verbose $object .$prop ;
880
+ foreach ($definition in $object .$prop.psobject.properties ) {
881
+ write-verbose " Definition Name : $ ( $Definition.Name ) "
882
+ $Result.definitions += ((New-SchemaProperty - Name $definition.Name - Value ($definition.Value | ConvertTo-SchemaDefinition )))
883
+ }
884
+ }
837
885
else {
838
886
if ($Object .$prop.GetType ().IsArray)
839
887
{
0 commit comments