diff --git a/examples/docs/arrays.schema.md b/examples/docs/arrays.schema.md index a20bb6563b596a747bdaa3393ba2001ec6008acb..18624428a451bacd5911492803f5772c55f7b3fe 100644 --- a/examples/docs/arrays.schema.md +++ b/examples/docs/arrays.schema.md @@ -19,6 +19,7 @@ This is an example schema with examples for multiple array types and their const | Property | Type | Required | Defined by | |----------|------|----------|------------| +| [JoinTypelist](#jointypelist) | `array` | Optional | Arrays (this schema) | | [boollist](#boollist) | `boolean[]` | Optional | Arrays (this schema) | | [coordinatelist](#coordinatelist) | `number[][]` | Optional | Arrays (this schema) | | [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) | @@ -29,6 +30,114 @@ This is an example schema with examples for multiple array types and their const | [stringlistlist](#stringlistlist) | `string[][]` | Optional | Arrays (this schema) | | `*` | any | Additional | this schema *allows* additional properties | +## JoinTypelist + +An array of simple objects + +`JoinTypelist` + +* is optional +* type: `array` +* defined in this schema + +### JoinTypelist Type + + +Array type: `array` + +All items must be of the type: + +**One** of the following *conditions* need to be fulfilled. + + +#### Condition 1 + + +`object` with following properties: + + +| Property | Type | Required | +|----------|------|----------| +| `foo`| string | Optional | + + + +#### foo + +A simple string. + +`foo` + +* is optional +* type: `string` + +##### foo Type + + +`string` + + + + + + +##### foo Example + +```json +hello +``` + + + + +#### Condition 2 + + +`object` with following properties: + + +| Property | Type | Required | +|----------|------|----------| +| `bar`| string | Optional | + + + +#### bar + +A simple string. + +`bar` + +* is optional +* type: `string` + +##### bar Type + + +`string` + + + + + + +##### bar Example + +```json +world +``` + + + + + + + + + + + + ## boollist This is an array diff --git a/examples/generated-schemas/arrays.schema.json b/examples/generated-schemas/arrays.schema.json index 490e0e05ba5730829ed65b69e446549ada706774..6dd4ee829a4163153be1463ae48a5af767051d24 100644 --- a/examples/generated-schemas/arrays.schema.json +++ b/examples/generated-schemas/arrays.schema.json @@ -96,6 +96,40 @@ } } } + }, + "JoinTypelist": { + "type": "array", + "description": "An array of simple objects", + "items": { + "oneOf": [ + { + "type": "object", + "description": "A simple string.", + "properties": { + "foo": { + "type": "string", + "description": "A simple string.", + "examples": [ + "hello" + ] + } + } + }, + { + "type": "object", + "description": "Another simple string.", + "properties": { + "bar": { + "type": "string", + "description": "A simple string.", + "examples": [ + "world" + ] + } + } + } + ] + } } } } \ No newline at end of file diff --git a/examples/schemas/arrays.schema.json b/examples/schemas/arrays.schema.json index 9cc2660f110157c7de7e3306fb275da85cde571e..19b1a113c356956c658bfcf38c0efeb08a89deb5 100644 --- a/examples/schemas/arrays.schema.json +++ b/examples/schemas/arrays.schema.json @@ -12,31 +12,31 @@ "description": "This is an example schema with examples for multiple array types and their constraints.", "properties": { "list": { - "type":"array", + "type": "array", "description": "This is an array", "items": { "type": "string" } }, "listlist": { - "type":"array", + "type": "array", "description": "This is an array of arrays", "items": { "type": "array" } }, "stringlistlist": { - "type":"array", + "type": "array", "description": "This is an array of arrays of strings", "items": { "type": "array", "items": { - "type":"string" + "type": "string" } } }, "intlist": { - "type":"array", + "type": "array", "description": "This is an array", "items": { "type": "integer" @@ -45,7 +45,7 @@ "minItems": 1 }, "boollist": { - "type":"array", + "type": "array", "description": "This is an array", "items": { "type": "boolean" @@ -53,7 +53,7 @@ "minItems": 1 }, "numlist": { - "type":"array", + "type": "array", "description": "This is an array", "items": { "type": "number", @@ -62,7 +62,7 @@ "maxItems": 10 }, "coordinatelist": { - "type":"array", + "type": "array", "description": "This is an array of coordinates in three-dimensional space.", "items": { "type": "array", @@ -70,7 +70,7 @@ "maxItems": 3, "description": "A coordinate, specified by `x`, `y`, and `z` values", "items": { - "type":"number", + "type": "number", "minimum": 0, "maximum": 10 } @@ -91,11 +91,45 @@ "description": "The a property" }, "b": { - "type":"integer", + "type": "integer", "description": "The b property" } } } + }, + "JoinTypelist": { + "type": "array", + "description": "An array of simple objects", + "items": { + "oneOf": [ + { + "type": "object", + "description": "A simple string.", + "properties": { + "foo": { + "type": "string", + "description": "A simple string.", + "examples": [ + "hello" + ] + } + } + }, + { + "type": "object", + "description": "Another simple string.", + "properties": { + "bar": { + "type": "string", + "description": "A simple string.", + "examples": [ + "world" + ] + } + } + } + ] + } } } -} +} \ No newline at end of file diff --git a/spec/examples/arrays.schema.md b/spec/examples/arrays.schema.md index a20bb6563b596a747bdaa3393ba2001ec6008acb..18624428a451bacd5911492803f5772c55f7b3fe 100644 --- a/spec/examples/arrays.schema.md +++ b/spec/examples/arrays.schema.md @@ -19,6 +19,7 @@ This is an example schema with examples for multiple array types and their const | Property | Type | Required | Defined by | |----------|------|----------|------------| +| [JoinTypelist](#jointypelist) | `array` | Optional | Arrays (this schema) | | [boollist](#boollist) | `boolean[]` | Optional | Arrays (this schema) | | [coordinatelist](#coordinatelist) | `number[][]` | Optional | Arrays (this schema) | | [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) | @@ -29,6 +30,114 @@ This is an example schema with examples for multiple array types and their const | [stringlistlist](#stringlistlist) | `string[][]` | Optional | Arrays (this schema) | | `*` | any | Additional | this schema *allows* additional properties | +## JoinTypelist + +An array of simple objects + +`JoinTypelist` + +* is optional +* type: `array` +* defined in this schema + +### JoinTypelist Type + + +Array type: `array` + +All items must be of the type: + +**One** of the following *conditions* need to be fulfilled. + + +#### Condition 1 + + +`object` with following properties: + + +| Property | Type | Required | +|----------|------|----------| +| `foo`| string | Optional | + + + +#### foo + +A simple string. + +`foo` + +* is optional +* type: `string` + +##### foo Type + + +`string` + + + + + + +##### foo Example + +```json +hello +``` + + + + +#### Condition 2 + + +`object` with following properties: + + +| Property | Type | Required | +|----------|------|----------| +| `bar`| string | Optional | + + + +#### bar + +A simple string. + +`bar` + +* is optional +* type: `string` + +##### bar Type + + +`string` + + + + + + +##### bar Example + +```json +world +``` + + + + + + + + + + + + ## boollist This is an array diff --git a/templates/md/array-type.ejs b/templates/md/array-type.ejs index ad9c13f5a9e69823c5e61a999598b6d6e48f1890..12d2883c4a2ce44bcf514266953d783c8c447d2a 100644 --- a/templates/md/array-type.ejs +++ b/templates/md/array-type.ejs @@ -22,6 +22,8 @@ if (schema.items.type==="string") { %><%- include("object-type",{schema:schema.items,_:_}) %><% } else if (schema.items.type==="array") { %><%- include("array-type",{schema:schema.items,_:_, nested:true}) + %><% } else if (schema.items.anyOf!==undefined || schema.items.allOf!==undefined || schema.items.oneOf!==undefined) { + %><%- include("join-type",{schema:schema.items,_:_,schemas:schema.items.anyOf || schema.items.allOf || schema.items.oneOf, ejs:ejs}) %> %><% } else if (schema.items.$ref!==undefined) { %><%- include("referenced-type",{schema:schema.items,_:_}) %> <% } else { %>