|
| 1 | +TOPIC |
| 2 | + about_schema_classes |
| 3 | + |
| 4 | +SHORT DESCRIPTION |
| 5 | + This module uses several custom classes in order to provide flexibility and |
| 6 | + functionality to the module and experience as a whole. |
| 7 | + |
| 8 | +LONG DESCRIPTION |
| 9 | + This module uses several custom classes in order to provide flexibility and |
| 10 | + functionality to the module and experience as a whole. The SchemaModule |
| 11 | + classes are derived from the JSON Schema reference pages for draft 7.0. They |
| 12 | + contain all the attributes for each object as well as some support methods |
| 13 | + to make working with the objects easier. |
| 14 | + As they are PowerShell Custom Types, they can't be used directly within |
| 15 | + PowerShell. In order to take advantage of these types in your own scripts |
| 16 | + you may need to add a "using" statement, or leverage the New-SchemaElement |
| 17 | + function to instantiate the objects in the PowerShell console. |
| 18 | + |
| 19 | +Classes |
| 20 | + The SchemaModule classes are derived from the JSON Schema reference pages |
| 21 | + for draft 7.0. They contain all the attributes for each object as well as |
| 22 | + some support methods to make working with the objects easier. |
| 23 | + |
| 24 | + SCHEMADOCUMENT |
| 25 | + This class is really modified object that contains the $schema attribute as |
| 26 | + well as validation on what values can be present for that attribute. |
| 27 | + Schema Object |
| 28 | + Schema Keyword |
| 29 | + Schema Types |
| 30 | + |
| 31 | + SCHEMASTRING |
| 32 | + The string type is used for strings of text. It may contain Unicode |
| 33 | + characters. |
| 34 | + Schema String |
| 35 | + Schema Types |
| 36 | + |
| 37 | + SCHEMAINTEGER |
| 38 | + The integer type is used for integral numbers. In PowerShell this is an |
| 39 | + int32 |
| 40 | + Schema Integer |
| 41 | + Schema Types |
| 42 | + |
| 43 | + SCHEMANUMBER |
| 44 | + The number type is used for any numeric type, either integers or floating |
| 45 | + point numbers. In PowerShell this is a double. |
| 46 | + Schema Number |
| 47 | + Schema Types |
| 48 | + |
| 49 | + SCHEMABOOLEAN |
| 50 | + The boolean type matches only two special values: true and false. Note that |
| 51 | + values that evaluate to true or false, such as 1 and 0, are not accepted by |
| 52 | + the schema. |
| 53 | + Schema Boolean |
| 54 | + Schema Types |
| 55 | + |
| 56 | + SCHEMAOBJECT |
| 57 | + Objects are the mapping type in JSON. They map "keys" to "values". In JSON, |
| 58 | + the "keys" must always be strings. Each of these pairs is conventionally |
| 59 | + referred to as a "property". |
| 60 | + Schema Object |
| 61 | + Schema Types |
| 62 | + |
| 63 | + SCHEMADEFINITION |
| 64 | + Sometimes we have small subschemas that are only intended for use in the |
| 65 | + current schema and it doesn't make sense to define them as separate schemas. |
| 66 | + Schema Definition |
| 67 | + Schema Types |
| 68 | + |
| 69 | + SCHEMAARRAY |
| 70 | + Arrays are used for ordered elements. In JSON, each element in an array may |
| 71 | + be of a different type. |
| 72 | + Schema Array |
| 73 | + Schema Types |
| 74 | + |
| 75 | +EXAMPLES |
| 76 | + String = New-SchemaElement -Type string |
| 77 | + |
| 78 | + $String |Get-Member |
| 79 | + |
| 80 | + |
| 81 | + TypeName: schemaString |
| 82 | + |
| 83 | + Name MemberType Definition |
| 84 | + ---- ---------- ---------- |
| 85 | + AddEnum Method void AddEnum(string enum) |
| 86 | + AddExample Method void AddExample(string example) |
| 87 | + Equals Method bool Equals(System.Object obj) |
| 88 | + GetHashCode Method int GetHashCode() |
| 89 | + GetType Method type GetType() |
| 90 | + ToString Method System.Object ToString() |
| 91 | + default Property string default {get;set;} |
| 92 | + description Property string description {get;set;} |
| 93 | + enum Property string[] enum {get;set;} |
| 94 | + examples Property string[] examples {get;set;} |
| 95 | + id Property string id {get;set;} |
| 96 | + maxLength Property int maxLength {get;set;} |
| 97 | + minLength Property int minLength {get;set;} |
| 98 | + pattern Property string pattern {get;set;} |
| 99 | + ref Property string ref {get;set;} |
| 100 | + title Property string title {get;set;} |
| 101 | + type Property string type {get;set;} |
| 102 | + |
| 103 | + |
| 104 | + $String.AddEnum(@('cat','dog')) |
| 105 | + |
| 106 | + $String |ConvertTo-Json |
| 107 | + { |
| 108 | + "type": "string", |
| 109 | + "examples": [ |
| 110 | + |
| 111 | + ], |
| 112 | + "id": null, |
| 113 | + "ref": null, |
| 114 | + "minLength": 0, |
| 115 | + "maxLength": 0, |
| 116 | + "pattern": null, |
| 117 | + "enum": [ |
| 118 | + "cat dog" |
| 119 | + ], |
| 120 | + "title": null, |
| 121 | + "description": null, |
| 122 | + "default": null |
| 123 | + } |
| 124 | + # |
| 125 | + |
| 126 | + This example shows how to create an object and access one of the methods |
| 127 | + |
| 128 | + $Schema = Get-SchemaDocument -Path 'D:\TEMP\test\schema-sample.json' |
| 129 | + $Schema |Get-Member |
| 130 | + |
| 131 | + |
| 132 | + TypeName: schemaDocument |
| 133 | + |
| 134 | + Name MemberType Definition |
| 135 | + ---- ---------- ---------- |
| 136 | + AddProperty Method System.Object AddProperty(System.Object property) |
| 137 | + Equals Method bool Equals(System.Object obj) |
| 138 | + Find Method System.Object Find(string item) |
| 139 | + GetHashCode Method int GetHashCode() |
| 140 | + GetProperty Method System.Object GetProperty(string PropertyName) |
| 141 | + GetType Method type GetType() |
| 142 | + ToObject Method System.Object ToObject(), System.Object ToObject(int Depth), System.Object ToObject(string PropertyName), System.Object ToObject(string PropertyName, int Depth) |
| 143 | + ToString Method System.Object ToString() |
| 144 | + additionalProperties Property bool additionalProperties {get;set;} |
| 145 | + default Property System.Object default {get;set;} |
| 146 | + definitions Property System.Object definitions {get;set;} |
| 147 | + description Property string description {get;set;} |
| 148 | + id Property string id {get;set;} |
| 149 | + properties Property System.Object properties {get;set;} |
| 150 | + required Property string[] required {get;set;} |
| 151 | + schema Property string schema {get;set;} |
| 152 | + title Property string title {get;set;} |
| 153 | + type Property string type {get;set;} |
| 154 | + |
| 155 | + |
| 156 | + $Schema.Find('printers') |
| 157 | + |
| 158 | + $id title description default items |
| 159 | + --- ----- ----------- ------- ----- |
| 160 | + #/properties/contents/items/anyOf/0/properties/printers The printers schema An explanation about the purpose of this instance. {} @{anyOf=System.Object[]} |
| 161 | + |
| 162 | + This is another example of using methods within a created object |
| 163 | + |
| 164 | +SEE ALSO |
| 165 | + Project Site |
| 166 | + Github Repo |
| 167 | + |
0 commit comments