Skip to content

Commit 259d3ff

Browse files
Merge pull request #41 from SchemaModule/epic-54
Epic 54
2 parents 39dbcb1 + 9898e86 commit 259d3ff

29 files changed

+1325
-3537
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
- Move code out of functions into classes
11+
- Better Error handling support
12+
13+
## [3.0.0] - 2021-11-24
14+
15+
### Added
16+
- Added support for processing definitions
17+
- Added schemaDefinition Class
18+
- Added type support for Definitions
19+
- Added ConvertTo-SchemaDefinition function
20+
- Added ToObject support for Arrays
21+
- Added Global:RawSchema variable to view incoming schema before processing
22+
23+
### Updated
24+
25+
- Find-SchemaElement handles arrays and definitions
26+
- ConvertTo-SchemaElement can now work with definitions properly
27+
- Get-SchemaDefinition has better support for actual definitions
1128

1229
## [2.0.0] - 2020-12-22
1330

README.md

554 Bytes

ConvertFrom-SchemaObject

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

ConvertFrom-SchemaDefinition

This function takes an object that has the format of a Schema Definition and converts it into the schemaDefinition class. It can also return as either the schemaDefinition class or a json string.

ConvertTo-SchemaElement

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

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ stages:
4949
command: push
5050
packagesToPush: '$(BUILD.REPOSITORY.LOCALPATH)\powershell\*.nupkg;'
5151
nuGetFeedType: external
52-
publishFeedCredentials: artifacts
52+
publishFeedCredentials: poshGallery
Binary file not shown.
Binary file not shown.

docs/ConvertFrom-SchemaArray.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,14 @@ Accept wildcard characters: False
102102
```
103103
104104
### CommonParameters
105-
106105
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).
107106
108107
## INPUTS
109108
110109
### None
111-
112110
## OUTPUTS
113111
114112
### System.Object[]
115-
116113
## NOTES
117114
118115
## RELATED LINKS

docs/ConvertFrom-SchemaObject.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,14 @@ Accept wildcard characters: False
115115
```
116116
117117
### CommonParameters
118-
119118
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).
120119
121120
## INPUTS
122121
123122
### None
124-
125123
## OUTPUTS
126124
127125
### System.Object
128-
129126
## NOTES
130127
131128
## RELATED LINKS

docs/ConvertTo-SchemaDefinition.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
external help file: schema-help.xml
3+
Module Name: schema
4+
online version: https://github.com/SchemaModule/PowerShell/blob/master/docs/ConvertTo-SchemaDefinition.md#convertto-schemadefinition
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertTo-SchemaDefinition
9+
10+
## SYNOPSIS
11+
12+
This function takes an object that has the format of a Schema Definition and
13+
converts it into the schemaDefinition class. It can also return as either the
14+
schemaDefinition class or a json string.
15+
16+
## SYNTAX
17+
18+
```
19+
ConvertTo-SchemaDefinition [[-Definition] <Object>] [-AsJson] [<CommonParameters>]
20+
```
21+
22+
## DESCRIPTION
23+
24+
This function takes an object that has the format of a Schema Definition and
25+
converts it into the schemaDefinition class. It can also return as either the
26+
schemaDefinition class or a json string.
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+
ConvertTo-SchemaDefinition -Definition $Schema.definitions.room
36+
37+
38+
type : object
39+
properties : @{Id=; Title;Description=}
40+
required :
41+
```
42+
43+
This example shows how to use the function to convert an object into a schema
44+
class.
45+
46+
47+
## PARAMETERS
48+
49+
### -AsJson
50+
51+
Allows the funciton to return a string in JSON format.
52+
53+
```yaml
54+
Type: System.Management.Automation.SwitchParameter
55+
Parameter Sets: (All)
56+
Aliases:
57+
58+
Required: False
59+
Position: Named
60+
Default value: None
61+
Accept pipeline input: False
62+
Accept wildcard characters: False
63+
```
64+
65+
### -Definition
66+
67+
This is a JSON Schema definition as defined by the json-schema.org (see related
68+
links below). This object is then converted into a PowerShell object that can be
69+
used like any other PowerShell object.
70+
71+
{
72+
"type": [
73+
"object"
74+
],
75+
"properties": {
76+
"Id": {
77+
"type": "string"
78+
},
79+
"Regions": {
80+
"type": "array",
81+
"items": {
82+
"$ref": "#/definitions/Region"
83+
}
84+
}
85+
},
86+
"required": [
87+
"Id",
88+
"Regions"
89+
]
90+
}
91+
92+
```yaml
93+
Type: System.Object
94+
Parameter Sets: (All)
95+
Aliases:
96+
97+
Required: True
98+
Position: 0
99+
Default value: None
100+
Accept pipeline input: False
101+
Accept wildcard characters: False
102+
```
103+
104+
### CommonParameters
105+
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).
106+
107+
## INPUTS
108+
109+
### None
110+
## OUTPUTS
111+
112+
### schemaDefinition
113+
This class is really modified object that contains the $schema attribute as well as validation on what values can be present for that attribute. Schema Definition (https://json-schema.org/understanding-json-schema/structuring.html#defs) Schema Keyword (https://json-schema.org/understanding-json-schema/reference/schema.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
114+
115+
## NOTES
116+
117+
## RELATED LINKS
118+
119+
[Get-SchemaDocument](https://github.com/SchemaModule/PowerShell/blob/master/docs/Get-SchemaDocument.md#get-schemadocument)
120+
121+
[New-SchemaProperty](https://github.com/SchemaModule/PowerShell/blob/master/docs/New-SchemaProperty.md#new-schemaproperty)
122+
123+
[About Classes](https://github.com/SchemaModule/PowerShell/blob/master/docs/about_Schema_Classes.md)
124+
125+
[JSON Schema Reference](https://json-schema.org/understanding-json-schema/reference/index.html)

docs/ConvertTo-SchemaElement.md

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SchemaModule classes.
1515
## SYNTAX
1616

1717
```
18-
ConvertTo-SchemaElement [-Object] <Object> [<CommonParameters>]
18+
ConvertTo-SchemaElement [-Object] <Object> [-IsRootSchema] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
@@ -71,6 +71,23 @@ Format-List CmdLet.
7171

7272
## PARAMETERS
7373

74+
### -IsRootSchema
75+
76+
This switch allows the function to know when it's working with the root of a
77+
schema document versus a regular object.
78+
79+
```yaml
80+
Type: System.Management.Automation.SwitchParameter
81+
Parameter Sets: (All)
82+
Aliases:
83+
84+
Required: False
85+
Position: Named
86+
Default value: None
87+
Accept pipeline input: False
88+
Accept wildcard characters: False
89+
```
90+
7491
### -Object
7592
7693
This is a JSON Schema object as defined by the json-schema.org (see related links
@@ -106,79 +123,33 @@ Accept wildcard characters: False
106123
```
107124
108125
### CommonParameters
109-
110126
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).
111127
112128
## INPUTS
113129
114130
### None
115-
116131
## OUTPUTS
117132
118133
### schemaDocument
119-
120-
This class is really modified object that contains the $schema attribute as well
121-
as validation on what values can be present for that attribute.
122-
123-
[Schema Object](https://json-schema.org/understanding-json-schema/reference/object.html)
124-
125-
[Schema Keyword](https://json-schema.org/understanding-json-schema/reference/schema.html)
126-
127-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
134+
This class is really modified object that contains the $schema attribute as well as validation on what values can be present for that attribute. Schema Object (https://json-schema.org/understanding-json-schema/reference/object.html) Schema Keyword (https://json-schema.org/understanding-json-schema/reference/schema.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
128135
129136
### schemaString
130-
131-
The string type is used for strings of text. It may contain Unicode characters.
132-
133-
[Schema String](https://json-schema.org/understanding-json-schema/reference/string.html)
134-
135-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
137+
The string type is used for strings of text. It may contain Unicode characters. Schema String (https://json-schema.org/understanding-json-schema/reference/string.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
136138
137139
### schemaInteger
138-
139-
The integer type is used for integral numbers. In PowerShell this is an int32
140-
141-
[Schema Integer](http://json-schema.org/understanding-json-schema/reference/numeric.html#integer)
142-
143-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
140+
The integer type is used for integral numbers. In PowerShell this is an int32 Schema Integer (http://json-schema.org/understanding-json-schema/reference/numeric.html#integer) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
144141
145142
### schemaNumber
146-
147-
The number type is used for any numeric type, either integers or floating point
148-
numbers. In PowerShell this is a double.
149-
150-
[Schema Number](http://json-schema.org/understanding-json-schema/reference/numeric.html#number)
151-
152-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
143+
The number type is used for any numeric type, either integers or floating point numbers. In PowerShell this is a double. Schema Number (http://json-schema.org/understanding-json-schema/reference/numeric.html#number) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
153144
154145
### schemaBoolean
155-
156-
The boolean type matches only two special values: true and false. Note that
157-
values that evaluate to true or false, such as 1 and 0, are not accepted by the
158-
schema.
159-
160-
[Schema Boolean](http://json-schema.org/understanding-json-schema/reference/boolean.html)
161-
162-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
146+
The boolean type matches only two special values: true and false. Note that values that evaluate to true or false, such as 1 and 0, are not accepted by the schema. Schema Boolean (http://json-schema.org/understanding-json-schema/reference/boolean.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
163147
164148
### schemaObject
165-
166-
Objects are the mapping type in JSON. They map "keys" to "values". In JSON, the
167-
"keys" must always be strings. Each of these pairs is conventionally referred
168-
to as a "property".
169-
170-
[Schema Object](https://json-schema.org/understanding-json-schema/reference/object.html)
171-
172-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
149+
Objects are the mapping type in JSON. They map "keys" to "values". In JSON, the "keys" must always be strings. Each of these pairs is conventionally referred to as a "property". Schema Object (https://json-schema.org/understanding-json-schema/reference/object.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
173150
174151
### schemaArray
175-
176-
Arrays are used for ordered elements. In JSON, each element in an array may be
177-
of a different type.
178-
179-
[Schema Array](https://json-schema.org/understanding-json-schema/reference/array.html)
180-
181-
[Schema Types](https://json-schema.org/understanding-json-schema/reference/type.html)
152+
Arrays are used for ordered elements. In JSON, each element in an array may be of a different type. Schema Array (https://json-schema.org/understanding-json-schema/reference/array.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
182153
183154
## NOTES
184155

0 commit comments

Comments
 (0)