Skip to content

Issue 13 #14

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

Merged
merged 5 commits into from
Sep 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions schema/schema.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ function Get-Document {
)

process {
Write-Verbose $Path;
try {
Write-Verbose "Clearing Error Variables";
$ErrorActionPreference = 'Stop';
$Error.Clear();

Write-Verbose "Parsing Path param";
$Schema = [System.UriBuilder]::new($Path);
Write-Verbose $Schema;

switch ($Schema.Scheme) {
'file' {
Write-Verbose "Incoming Filepath";
Get-Content -Path $Path | ConvertFrom-Json;
}
'https' {
Write-Verbose "Incoming HTTPs path";
Invoke-WebRequest -UseBasicParsing -Uri $Path | Select-Object -ExpandProperty Content | ConvertFrom-Json;
}
'http' {
Write-Verbose "Incoming HTTP path";
Invoke-WebRequest -UseBasicParsing -Uri $Path | Select-Object -ExpandProperty Content | ConvertFrom-Json;
}
}
Expand All @@ -43,24 +50,32 @@ function Get-Object {
)

process {
Write-Verbose $SchemaDocument;
$Properties = $SchemaDocument.properties | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name;
Write-Verbose "Setting up output object";
$Members = @{};
foreach ($Property in $Properties) {
Write-Verbose "Property: $($Property)";
switch ($SchemaDocument.properties.$Property.type) {
'object' {
Write-Verbose "Add Object to output object";
$Members.Add($Property, (New-Object -TypeName psobject -Property @{}))
}
'array' {
Write-Verbose "Add Array to output object";
$Members.Add($Property, @())
}
'string' {
Write-Verbose "Add String to output object";
$Members.Add($Property, "")
}
'number' {
Write-Verbose "Add Number to output object";
$Members.Add($Property, [Int16]"")
}
}
}
Write-Verbose "Return JSON PowerShell object";
New-Object -TypeName psobject -Property $Members;
}
}
Expand All @@ -75,24 +90,32 @@ function Get-Array {
)

process {
Write-Verbose $SchemaDocument;
$Properties = $SchemaDocument.items.anyOf.properties | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name;
Write-Verbose "Setting up output object";
$Members = @{};
foreach ($Property in $Properties) {
Write-Verbose "Property: $($Property)";
switch ($SchemaDocument.items.anyOf.properties.$Property.type) {
'object' {
Write-Verbose "Add Object to output object";
$Members.Add($Property, (New-Object -TypeName psobject -Property @{}))
}
'array' {
Write-Verbose "Add Array to output object";
$Members.Add($Property, @())
}
'string' {
Write-Verbose "Add String to output object";
$Members.Add($Property, "")
}
'number' {
Write-Verbose "Add Number to output object";
$Members.Add($Property, [Int16]"")
}
}
}
Write-Verbose "Return JSON PowerShell object";
New-Object -TypeName psobject -Property $Members;
}
}
Expand All @@ -108,10 +131,14 @@ function Get-Property {
)

process {
Write-Verbose $SchemaDocument;
Write-Verbose $Name;
if ($Name) {
Write-Verbose "Return specific Property";
$SchemaDocument.properties.$Name;
}
else {
Write-Verbose "Return all properties";
$SchemaDocument.properties;
}
}
Expand Down