Skip to content

Issue 44 PR #45

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
Feb 19, 2022
Merged
Show file tree
Hide file tree
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
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions docs/ConvertTo-SchemaDefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ schemaDefinition class or a json string.
## SYNTAX

```
ConvertTo-SchemaDefinition [[-Definition] <Object>] [-AsJson] [<CommonParameters>]
ConvertTo-SchemaDefinition [[-Definition] <Object>] [-AsJson] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -43,7 +43,6 @@ required :
This example shows how to use the function to convert an object into a schema
class.


## PARAMETERS

### -AsJson
Expand Down Expand Up @@ -94,10 +93,10 @@ Type: System.Object
Parameter Sets: (All)
Aliases:

Required: True
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

Expand Down
18 changes: 17 additions & 1 deletion docs/Get-SchemaDocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This function will return a schemaDocument object of the input Schema.
## SYNTAX

```
Get-SchemaDocument [[-Path] <String>] [<CommonParameters>]
Get-SchemaDocument [[-Path] <String>] [-Headers <Hashtable>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -63,6 +63,22 @@ This example passes a json schema file into the function.

## PARAMETERS

### -Headers

This should be a hashtable of key/value pairs that the server is expecting.

```yaml
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Path

This can be a filepath or URL, the function does light validation on the input.
Expand Down
2 changes: 0 additions & 2 deletions docs/New-SchemaBoolean.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,9 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS

### None

## OUTPUTS

### schemaBoolean

## NOTES

## RELATED LINKS
Expand Down
167 changes: 167 additions & 0 deletions schema/about_Schema_Classes.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
TOPIC
about_schema_classes

SHORT DESCRIPTION
This module uses several custom classes in order to provide flexibility and
functionality to the module and experience as a whole.

LONG DESCRIPTION
This module uses several custom classes in order to provide flexibility and
functionality to the module and experience as a whole. The SchemaModule
classes are derived from the JSON Schema reference pages for draft 7.0. They
contain all the attributes for each object as well as some support methods
to make working with the objects easier.
As they are PowerShell Custom Types, they can't be used directly within
PowerShell. In order to take advantage of these types in your own scripts
you may need to add a "using" statement, or leverage the New-SchemaElement
function to instantiate the objects in the PowerShell console.

Classes
The SchemaModule classes are derived from the JSON Schema reference pages
for draft 7.0. They contain all the attributes for each object as well as
some support methods to make working with the objects easier.

SCHEMADOCUMENT
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
Schema Keyword
Schema Types

SCHEMASTRING
The string type is used for strings of text. It may contain Unicode
characters.
Schema String
Schema Types

SCHEMAINTEGER
The integer type is used for integral numbers. In PowerShell this is an
int32
Schema Integer
Schema Types

SCHEMANUMBER
The number type is used for any numeric type, either integers or floating
point numbers. In PowerShell this is a double.
Schema Number
Schema Types

SCHEMABOOLEAN
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
Schema Types

SCHEMAOBJECT
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
Schema Types

SCHEMADEFINITION
Sometimes we have small subschemas that are only intended for use in the
current schema and it doesn't make sense to define them as separate schemas.
Schema Definition
Schema Types

SCHEMAARRAY
Arrays are used for ordered elements. In JSON, each element in an array may
be of a different type.
Schema Array
Schema Types

EXAMPLES
String = New-SchemaElement -Type string

$String |Get-Member


TypeName: schemaString

Name MemberType Definition
---- ---------- ----------
AddEnum Method void AddEnum(string enum)
AddExample Method void AddExample(string example)
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method System.Object ToString()
default Property string default {get;set;}
description Property string description {get;set;}
enum Property string[] enum {get;set;}
examples Property string[] examples {get;set;}
id Property string id {get;set;}
maxLength Property int maxLength {get;set;}
minLength Property int minLength {get;set;}
pattern Property string pattern {get;set;}
ref Property string ref {get;set;}
title Property string title {get;set;}
type Property string type {get;set;}


$String.AddEnum(@('cat','dog'))

$String |ConvertTo-Json
{
"type": "string",
"examples": [

],
"id": null,
"ref": null,
"minLength": 0,
"maxLength": 0,
"pattern": null,
"enum": [
"cat dog"
],
"title": null,
"description": null,
"default": null
}
#

This example shows how to create an object and access one of the methods

$Schema = Get-SchemaDocument -Path 'D:\TEMP\test\schema-sample.json'
$Schema |Get-Member


TypeName: schemaDocument

Name MemberType Definition
---- ---------- ----------
AddProperty Method System.Object AddProperty(System.Object property)
Equals Method bool Equals(System.Object obj)
Find Method System.Object Find(string item)
GetHashCode Method int GetHashCode()
GetProperty Method System.Object GetProperty(string PropertyName)
GetType Method type GetType()
ToObject Method System.Object ToObject(), System.Object ToObject(int Depth), System.Object ToObject(string PropertyName), System.Object ToObject(string PropertyName, int Depth)
ToString Method System.Object ToString()
additionalProperties Property bool additionalProperties {get;set;}
default Property System.Object default {get;set;}
definitions Property System.Object definitions {get;set;}
description Property string description {get;set;}
id Property string id {get;set;}
properties Property System.Object properties {get;set;}
required Property string[] required {get;set;}
schema Property string schema {get;set;}
title Property string title {get;set;}
type Property string type {get;set;}


$Schema.Find('printers')

$id title description default items
--- ----- ----------- ------- -----
#/properties/contents/items/anyOf/0/properties/printers The printers schema An explanation about the purpose of this instance. {} @{anyOf=System.Object[]}

This is another example of using methods within a created object

SEE ALSO
Project Site
Github Repo

Loading