From 41b34d246ecda380e3a744ca9680a4c5912a853b Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Thu, 14 Dec 2017 15:47:50 +0000 Subject: [PATCH] [trivial] nested array formatting --- examples/docs/arrays.schema.md | 53 +++++++++++++++++-- examples/docs/examples.schema.md | 8 +-- examples/generated-schemas/arrays.schema.json | 16 ++++++ .../generated-schemas/examples.schema.json | 8 +-- templates/md/array-type.ejs | 15 ++++-- 5 files changed, 85 insertions(+), 15 deletions(-) diff --git a/examples/docs/arrays.schema.md b/examples/docs/arrays.schema.md index f7dd628..8b8c786 100644 --- a/examples/docs/arrays.schema.md +++ b/examples/docs/arrays.schema.md @@ -25,6 +25,7 @@ This is an example schema with examples for multiple array types and their const | [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) | | [boollist](#boollist) | `boolean[]` | Optional | Arrays (this schema) | | [numlist](#numlist) | `number[]` | Optional | Arrays (this schema) | +| [coordinatelist](#coordinatelist) | `number[][]` | Optional | Arrays (this schema) | ## list @@ -51,6 +52,7 @@ All items must be of the type: + ## listlist This is an array of arrays @@ -64,9 +66,9 @@ This is an array of arrays ### listlist Type -Array type: `array[]` +Nested array type: `array` + -All items must be of the type: Array type: `array` @@ -75,6 +77,8 @@ Array type: `array` + + ## stringlistlist This is an array of arrays of strings @@ -88,9 +92,9 @@ This is an array of arrays of strings ### stringlistlist Type -Array type: `string[][]` +Nested array type: `string[]` + -All items must be of the type: Array type: `string[]` All items must be of the type: @@ -105,6 +109,8 @@ All items must be of the type: + + ## intlist This is an array @@ -130,6 +136,7 @@ All items must be of the type: + ## boollist This is an array @@ -153,6 +160,7 @@ All items must be of the type: + ## numlist This is an array @@ -177,3 +185,40 @@ All items must be of the type: + + +## coordinatelist + +This is an array of coordinates in three-dimensional space. + +`coordinatelist` +* is optional +* type: `number[][]` (nested array) +* no more than `10` items in the array +* defined in this schema + +### coordinatelist Type + + +Nested array type: `number[]` + + +Array type: `number[]` + +All items must be of the type: +`number` +* minimum value: `0` +* maximum value: `10` + + + + + + +A coordinate, specified by `x`, `y`, and `z` values + + + + + + diff --git a/examples/docs/examples.schema.md b/examples/docs/examples.schema.md index 96c2634..57f409e 100644 --- a/examples/docs/examples.schema.md +++ b/examples/docs/examples.schema.md @@ -19,15 +19,15 @@ This is an example schema with *multiple* examples. Too many examples? There can ```json { - "foo": "zip", - "bar": "zap" + "foo": "bi", + "bar": "bu" } ``` ```json { - "foo": "bi", - "bar": "bu" + "foo": "zip", + "bar": "zap" } ``` diff --git a/examples/generated-schemas/arrays.schema.json b/examples/generated-schemas/arrays.schema.json index a6707af..607a21b 100644 --- a/examples/generated-schemas/arrays.schema.json +++ b/examples/generated-schemas/arrays.schema.json @@ -60,6 +60,22 @@ "minimum": 10 }, "maxItems": 10 + }, + "coordinatelist": { + "type": "array", + "description": "This is an array of coordinates in three-dimensional space.", + "items": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "description": "A coordinate, specified by `x`, `y`, and `z` values", + "items": { + "type": "number", + "minimum": 0, + "maximum": 10 + } + }, + "maxItems": 10 } } } \ No newline at end of file diff --git a/examples/generated-schemas/examples.schema.json b/examples/generated-schemas/examples.schema.json index 2a96fb9..d46f1b7 100644 --- a/examples/generated-schemas/examples.schema.json +++ b/examples/generated-schemas/examples.schema.json @@ -31,13 +31,13 @@ "bar" ], "examples": [ - { - "foo": "zip", - "bar": "zap" - }, { "foo": "bi", "bar": "bu" + }, + { + "foo": "zip", + "bar": "zap" } ] } \ No newline at end of file diff --git a/templates/md/array-type.ejs b/templates/md/array-type.ejs index 76f74d7..0799bdd 100644 --- a/templates/md/array-type.ejs +++ b/templates/md/array-type.ejs @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> - +<% if (schema.items!==undefined&&schema.items.type==="array") { %> +Nested array type: <%=schema.items.simpletype %> +<% } else { %> Array type: <%=schema.simpletype %> +<% } %> <% if (schema.items!==undefined) { %> - -All items must be of the type:<% +<% if (!(schema.items!==undefined&&schema.items.type==="array")) { %> +All items must be of the type:<% } if (schema.items.type==="string") { %><%- include("string-type",{schema:schema.items,_:_}) %><% } else if (schema.items.type==="number"||schema.items.type==="integer") { @@ -27,4 +30,10 @@ Unknown type `<%= schema.type %>`. <% } %> +<% if (schema.items.description!==undefined) { %> + +<%=schema.items.description %> + +<% } %> + <% } %> -- GitLab