Skip to content

Commit df769a4

Browse files
Merge pull request #34 from SchemaModule/dev
Version 2.0 Release
2 parents 7e5f70b + 39dbcb1 commit df769a4

32 files changed

+9811
-521
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,76 @@
11
# Changelog
2+
23
All changes to this module should be reflected in this document.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

78
## Unreleased
89

10+
- Move code out of functions into classes
11+
12+
## [2.0.0] - 2020-12-22
13+
14+
### Added
15+
16+
- Added classes to define JSON schema objects
17+
- Added utility methods to classes
18+
- Added Functions to support the classes
19+
- New-SchemaElement
20+
- New-SchemaString
21+
- New-SchemaInteger
22+
- New-SchemaNumber
23+
- New-SchemaProperty
24+
- New-SchemaBoolean
25+
- Get-SchemaDefinition
26+
- Get-SchemaReference
27+
- Find-SchemaElement
28+
- ConvertTo-SchemaElement
29+
- ConvertFrom-SchemaObject
30+
- ConvertFrom-SchemaArray
31+
- Format-SchemaDocument
32+
- Added support for types (schema.types.ps1xml)
33+
- Added support for formatting (schema.format.ps1xml)
34+
35+
### Updated
36+
37+
- Get-SchemaDocument has been udpated to work with the new functions
38+
39+
### Removed
40+
41+
- Get-SchemaArray
42+
- Get-SchemaObject
43+
- Get-SchemaProperty
44+
945
## [1.1.0] - 2020-09-11
46+
1047
### Added
48+
1149
- Updatable Help Support
1250

1351
## [1.0.0] - 2020-09-09
52+
1453
### Added
54+
1555
- Updated documentation and external help
1656
- CHNAGELOG added
1757
- psakefile added
1858
- Added JSON logo
1959

2060
### Changed
61+
2162
- README
2263
- Definition File updated with URLs and new version
2364

2465
### Fixed
66+
2567
- Missing some JSON data types, bool and int
2668
- Write-Verbose acts different for arrays, so corrected the output
2769

2870
## [0.0.1] - 2020-09-08
71+
2972
### Added
73+
3074
- Repository Created
3175
- Module manifest created
3276
- Module file copied from outside repository

README.md

1.11 KB
Latest Version Azure Pipelines PowerShell Gallery Github Release Issues Forks License
Latest Version Build Status Powershell Gallery Github Release GitHub issues GitHub forks GitHub license

About

The SchemaModule project grew out of a need to create PowerShell objects from a well-defined JSON schema. The functions included with this module should help a developer leverage objects and properties to create objects on-demand. The intended use-case is for this module to be used inside a script or other module to faciliate the creation of objects and ultimately validation.

Function Documentation

Below is the list of current functions and their documentation.

Latest Version PowerShell Gallery Build Status Project Board Issues License
Latest Version Powershell Gallery Build Status Board Status GitHub issues GitHub license

schema Module

Description

A PowerShell Module for working with JSON Schema documents

schema Cmdlets

This function returns the object from an array within the Json Schema.

This function takes the schemaArray object and converts it into a PowerShell array that can be nicely output as a JSON string.

ConvertFrom-SchemaObject

This function takes the schemaObject object and converts it into a PowerShell object that can be nicely output as a JSON string.

This function takes the output of ConvertFrom-Json CmdLet and converts it into SchemaModule classes.

Find-SchemaElement

This function provides the ability to find objects within the JSON schema either by Name, by Type or by a Path.

Format-SchemaDocument

A simple schema linter

Get-SchemaDefinition

A function to follow the Definition keyword and return the referenced schema

Get-SchemaDocument

This function will return a PowerShellschemaDocument object of the input Schema.

This function returns an object from the Json Schema.

A function to follow the ref keyword and return the referenced schema

This function returns one ore more properties from a Json Schema object.

Documentation

This project uses PlatyPS for framing and updating the help files and external help used by the functions.

Automation

A few things within each module are automated by psake such as the functions that are exported, as well as the README file for each module.

Syntax Checking

PSScriptAnalyzer is used to check the code against a set of standards, this ensures that the code works as expected when ran.

A function to create new SchemaModule objects

New-SchemaInteger

A function to create new Schema Integer object

New-SchemaBoolean

A function to create new Schema Boolean object

New-SchemaNumber

A function to create new Schema Number object

New-SchemaProperty

A Function to create either an object property or array item

New-SchemaString

A function to create new Schema String object

cabs/schema_b75e69d4-47bc-4ac6-b7d7-df9a36e08bbe_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>en-US</UICultureName>
7-
<UICultureVersion>1.1.0</UICultureVersion>
7+
<UICultureVersion>2.0.0</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>
Binary file not shown.
Binary file not shown.

docs/ConvertFrom-SchemaArray.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
external help file: schema-help.xml
3+
Module Name: schema
4+
online version: https://github.com/SchemaModule/PowerShell/blob/master/docs/ConvertFrom-SchemaArray.md#convertfrom-schemaarray
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertFrom-SchemaArray
9+
10+
## SYNOPSIS
11+
12+
This function takes the schemaArray object and converts it into a PowerShell array
13+
that can be nicely output as a JSON string.
14+
15+
## SYNTAX
16+
17+
```
18+
ConvertFrom-SchemaArray [-Array] <Object> [[-Depth] <Int32>] [<CommonParameters>]
19+
```
20+
21+
## DESCRIPTION
22+
23+
This function takes the schemaArray object and converts it into a PowerShell array
24+
that can be nicely output as a JSON string. This function is useful when you need
25+
to output the JSON schema as a JSON object. This would have the effect of
26+
creating an empty JSON document based on the schema that was provided.
27+
28+
## EXAMPLES
29+
30+
### Example 1
31+
32+
```powershell
33+
PS C:\> $Schema = Get-SchemaDocument -Path 'D:\TEMP\test\schema-sample.json'
34+
35+
ConvertFrom-SchemaArray -Array $Schema.Find('printers')
36+
37+
brand capability model type
38+
----- ---------- ----- ----
39+
```
40+
41+
Take an object defined in a JSON schema and convert it into a custom PowerShell
42+
object.
43+
44+
## PARAMETERS
45+
46+
### -Array
47+
48+
This is a JSON Schema Array as defined by the json-schema.org (see related links
49+
below). This array is then converted into a PowerShell object that can be used
50+
like any other PowerShell object.
51+
52+
{
53+
"type": "array",
54+
"additionalItems": true,
55+
"id": "#/properties/contents/items/anyOf/0/properties/printers",
56+
"items": {
57+
"anyOf": [{
58+
"type": "object",
59+
"additionalProperties": true,
60+
"id": "#/properties/contents/items/anyOf/0/properties/printers/items/anyOf/0",
61+
"properties": "System.Collections.Hashtable",
62+
"required": "type capability brand model",
63+
"title": "The first anyOf schema",
64+
"description": "An explanation about the purpose of this instance.",
65+
"default": "",
66+
"enum": null
67+
}]
68+
},
69+
"title": "The printers schema",
70+
"description": "An explanation about the purpose of this instance.",
71+
"default": [
72+
]
73+
}
74+
75+
```yaml
76+
Type: System.Object
77+
Parameter Sets: (All)
78+
Aliases:
79+
80+
Required: True
81+
Position: 0
82+
Default value: None
83+
Accept pipeline input: False
84+
Accept wildcard characters: False
85+
```
86+
87+
### -Depth
88+
89+
The Depth parameter defines the number of levers that are recursed in order to
90+
create the object.
91+
92+
```yaml
93+
Type: System.Int32
94+
Parameter Sets: (All)
95+
Aliases:
96+
97+
Required: False
98+
Position: 1
99+
Default value: None
100+
Accept pipeline input: False
101+
Accept wildcard characters: False
102+
```
103+
104+
### CommonParameters
105+
106+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
107+
108+
## INPUTS
109+
110+
### None
111+
112+
## OUTPUTS
113+
114+
### System.Object[]
115+
116+
## NOTES
117+
118+
## RELATED LINKS
119+
120+
[ConvertFrom-SchemaObject](https://github.com/SchemaModule/PowerShell/blob/master/docs/ConvertFrom-SchemaObject.md#convertfrom-schemaobject)
121+
122+
[About Classes](https://github.com/SchemaModule/PowerShell/blob/master/docs/about_Schema_Classes.md)
123+
124+
[JSON Schema Array](https://json-schema.org/understanding-json-schema/reference/array.html)

docs/ConvertFrom-SchemaObject.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
external help file: schema-help.xml
3+
Module Name: schema
4+
online version: https://github.com/SchemaModule/PowerShell/blob/master/docs/ConvertFrom-SchemaObject.md#convertfrom-schemaobject
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertFrom-SchemaObject
9+
10+
## SYNOPSIS
11+
12+
This function takes the schemaObject object and converts it into a PowerShell object
13+
that can be nicely output as a JSON string.
14+
15+
## SYNTAX
16+
17+
```
18+
ConvertFrom-SchemaObject [-Object] <Object> [[-Depth] <Int32>] [<CommonParameters>]
19+
```
20+
21+
## DESCRIPTION
22+
23+
This function takes the schemaObject object and converts it into a PowerShell object
24+
that can be nicely output as a JSON string. This function is useful when you need
25+
to output the JSON schema as a JSON object. This would have the effect of
26+
creating an empty JSON document based on the schema that was provided.
27+
28+
## EXAMPLES
29+
30+
### Example 1
31+
32+
```powershell
33+
PS C:\> $Schema = Get-SchemaDocument -Path 'D:\TEMP\test\schema-sample.json'
34+
35+
ConvertFrom-SchemaObject -Object $Schema
36+
37+
38+
$schema : http://json-schema.org/draft-07/schema#
39+
$id : http://example.com/example.json
40+
width :
41+
depth :
42+
closet : False
43+
room :
44+
contents : {System.Object}
45+
exterioraccess : False
46+
```
47+
48+
Take an object defined in a JSON schema and convert it into a custom PowerShell
49+
object.
50+
51+
## PARAMETERS
52+
53+
### -Depth
54+
55+
The Depth parameter defines the number of levers that are recursed in order to
56+
create the object.
57+
58+
```yaml
59+
Type: System.Int32
60+
Parameter Sets: (All)
61+
Aliases:
62+
63+
Required: False
64+
Position: 1
65+
Default value: None
66+
Accept pipeline input: False
67+
Accept wildcard characters: False
68+
```
69+
70+
### -Object
71+
72+
This is a JSON Schema object as defined by the json-schema.org (see related links
73+
below). This object is then converted into a PowerShell object that can be used
74+
like any other PowerShell object.
75+
76+
{
77+
"type": "object",
78+
"schema": "<http://json-schema.org/draft-07/schema>#",
79+
"additionalProperties": true,
80+
"definitions": null,
81+
"id": "http://example.com/example.json",
82+
"properties": {
83+
"width": "schemaString",
84+
"depth": "schemaString",
85+
"closet": "schemaBoolean",
86+
"room": "schemaString",
87+
"contents": "schemaArray",
88+
"exterioraccess": "schemaBoolean"
89+
},
90+
"required": [
91+
"room",
92+
"width",
93+
"depth",
94+
"closet",
95+
"exterioraccess",
96+
"contents"
97+
],
98+
"title": "The root schema",
99+
"description": "The root schema comprises the entire JSON document.",
100+
"default": {
101+
102+
}
103+
}
104+
105+
```yaml
106+
Type: System.Object
107+
Parameter Sets: (All)
108+
Aliases:
109+
110+
Required: True
111+
Position: 0
112+
Default value: None
113+
Accept pipeline input: False
114+
Accept wildcard characters: False
115+
```
116+
117+
### CommonParameters
118+
119+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
120+
121+
## INPUTS
122+
123+
### None
124+
125+
## OUTPUTS
126+
127+
### System.Object
128+
129+
## NOTES
130+
131+
## RELATED LINKS
132+
133+
[ConvertFrom-SchemaArray](https://github.com/SchemaModule/PowerShell/blob/master/docs/ConvertFrom-SchemaArray.md#convertfrom-schemaarray)
134+
135+
[About Classes](https://github.com/SchemaModule/PowerShell/blob/master/docs/about_Schema_Classes.md)
136+
137+
[JSON Schema Object](https://json-schema.org/understanding-json-schema/reference/object.html)

0 commit comments

Comments
 (0)