Public/Get-DattoApiSchema.ps1
|
function Get-DattoApiSchema { <# .SYNOPSIS Lists schemas from the bundled Datto OpenAPI contract. .DESCRIPTION Provides offline access to every component schema in the supplied Datto API documentation. Use -Detailed to return the complete schema object, including nested properties, references, examples, nullability, and enums. .PARAMETER Name Filters schema names. Wildcards are supported. .PARAMETER Detailed Includes the complete OpenAPI schema object. .EXAMPLE Get-DattoApiSchema .EXAMPLE Get-DattoApiSchema -Name 'Saas*' -Detailed .OUTPUTS PSCustomObject #> [CmdletBinding()] param( [Parameter(Position = 0)] [SupportsWildcards()] [string]$Name = '*', [Parameter()] [switch]$Detailed ) $spec = Get-DattoApiSpecificationDocument foreach ($schemaProperty in $spec.components.schemas.PSObject.Properties) { if ($schemaProperty.Name -notlike $Name) { continue } $schema = $schemaProperty.Value $properties = @() if ($schema.PSObject.Properties.Name -contains 'properties') { $properties = @($schema.properties.PSObject.Properties.Name) } $required = @() if ($schema.PSObject.Properties.Name -contains 'required') { $required = @($schema.required) } $typeValue = '' $descriptionValue = '' if ($schema.PSObject.Properties.Name -contains 'type') { $typeValue = [string]$schema.type } elseif ($schema.PSObject.Properties.Name -contains 'allOf') { $typeValue = 'allOf' } elseif ($schema.PSObject.Properties.Name -contains 'oneOf') { $typeValue = 'oneOf' } if ($schema.PSObject.Properties.Name -contains 'description') { $descriptionValue = [string]$schema.description } $record = [ordered]@{ Name = [string]$schemaProperty.Name Type = $typeValue Description = $descriptionValue PropertyCount = $properties.Count Properties = $properties Required = $required } if ($Detailed) { $record['Schema'] = $schema } [pscustomobject]$record } } |