From 61d1e4852427b8d657a0b320d3f318923fa6a4ac Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Wed, 24 Oct 2018 14:38:53 +0000 Subject: [PATCH] Support for nullable types and type choices #87 --- examples/docs/README.md | 1 + examples/docs/arrays.schema.md | 22 ++-- examples/docs/complex.schema.md | 22 ++-- examples/docs/constants.schema.md | 8 +- examples/docs/custom.schema.md | 10 +- examples/docs/deepextending.schema.md | 18 +-- examples/docs/definitions.schema.md | 12 +- examples/docs/enums.schema.md | 10 +- examples/docs/example.schema.md | 10 +- examples/docs/examples.schema.md | 10 +- examples/docs/extending.schema.md | 16 +-- examples/docs/identifiable.schema.md | 8 +- examples/docs/simple.schema.md | 8 +- examples/docs/simpletypes.schema.md | 40 +++---- examples/docs/stabilizing.schema.md | 8 +- examples/docs/typearrays.schema.md | 104 ++++++++++++++++++ .../generated-schemas/typearrays.schema.json | 46 ++++++++ examples/schemas/typearrays.schema.json | 36 ++++++ lib/markdownWriter.js | 17 +++ spec/examples/README.md | 1 + spec/examples/arrays.schema.md | 22 ++-- spec/examples/complex.schema.md | 22 ++-- spec/examples/constants.schema.md | 8 +- spec/examples/custom.schema.md | 10 +- spec/examples/deepextending.schema.md | 18 +-- spec/examples/definitions.schema.md | 12 +- spec/examples/enums.schema.md | 10 +- spec/examples/example.schema.md | 10 +- spec/examples/examples.schema.md | 10 +- spec/examples/extending.schema.md | 16 +-- spec/examples/identifiable.schema.md | 8 +- spec/examples/simple.schema.md | 8 +- spec/examples/simpletypes.schema.md | 40 +++---- spec/examples/stabilizing.schema.md | 8 +- spec/examples/typearrays.schema.md | 104 ++++++++++++++++++ spec/lib/integrationTest.spec.js | 2 +- templates/md/boolean-type.ejs | 2 +- templates/md/multiple-type.ejs | 13 +++ templates/md/null-type.ejs | 10 ++ templates/md/number-type.ejs | 2 +- templates/md/object-type.ejs | 2 +- templates/md/properties.ejs | 10 +- templates/md/property.ejs | 4 + templates/md/string-type.ejs | 2 +- 44 files changed, 548 insertions(+), 212 deletions(-) create mode 100644 examples/docs/typearrays.schema.md create mode 100644 examples/generated-schemas/typearrays.schema.json create mode 100644 examples/schemas/typearrays.schema.json create mode 100644 spec/examples/typearrays.schema.md create mode 100644 templates/md/multiple-type.ejs create mode 100644 templates/md/null-type.ejs diff --git a/examples/docs/README.md b/examples/docs/README.md index cbf8be8..f6545c1 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -22,6 +22,7 @@ * [Simple](./simple.schema.md) – `https://example.com/schemas/simple` (Unknown) * [Simple Types](./simpletypes.schema.md) – `https://example.com/schemas/simpletypes` (Unknown) * [Stabilizing](./stabilizing.schema.md) – `https://example.com/schemas/stabilizing` (Stabilizing) +* [Type Arrays](./typearrays.schema.md) – `https://example.com/schemas/typearrays` (Unknown) ## /subdir/ diff --git a/examples/docs/arrays.schema.md b/examples/docs/arrays.schema.md index 74c7371..4ed3a03 100644 --- a/examples/docs/arrays.schema.md +++ b/examples/docs/arrays.schema.md @@ -17,17 +17,17 @@ This is an example schema with examples for multiple array types and their const # Arrays Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [boollist](#boollist) | `boolean[]` | Optional | Arrays (this schema) | -| [coordinatelist](#coordinatelist) | `number[][]` | Optional | Arrays (this schema) | -| [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) | -| [list](#list) | `string[]` | Optional | Arrays (this schema) | -| [listlist](#listlist) | `array[]` | Optional | Arrays (this schema) | -| [numlist](#numlist) | `number[]` | Optional | Arrays (this schema) | -| [objectlist](#objectlist) | `object[]` | Optional | Arrays (this schema) | -| [stringlistlist](#stringlistlist) | `string[][]` | Optional | Arrays (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [boollist](#boollist) | `boolean[]` | Optional | No | Arrays (this schema) | +| [coordinatelist](#coordinatelist) | `number[][]` | Optional | No | Arrays (this schema) | +| [intlist](#intlist) | `integer[]` | Optional | No | Arrays (this schema) | +| [list](#list) | `string[]` | Optional | No | Arrays (this schema) | +| [listlist](#listlist) | `array[]` | Optional | No | Arrays (this schema) | +| [numlist](#numlist) | `number[]` | Optional | No | Arrays (this schema) | +| [objectlist](#objectlist) | `object[]` | Optional | No | Arrays (this schema) | +| [stringlistlist](#stringlistlist) | `string[][]` | Optional | No | Arrays (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## boollist diff --git a/examples/docs/complex.schema.md b/examples/docs/complex.schema.md index c813c30..d1faebd 100644 --- a/examples/docs/complex.schema.md +++ b/examples/docs/complex.schema.md @@ -23,17 +23,17 @@ This is an example schema that uses types defined in other schemas. # Complex References Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [and](#and) | complex | Optional | Complex References (this schema) | -| [or](#or) | complex | Optional | Complex References (this schema) | -| [refabstract](#refabstract) | `object` | **Required** | Complex References (this schema) | -| [reflist](#reflist) | Simple | Optional | Complex References (this schema) | -| [refnamed](#refnamed) | Simple | Optional | Complex References (this schema) | -| [xor](#xor) | complex | Optional | Complex References (this schema) | -| `int.*` | `integer` | Pattern | Complex References (this schema) | -| `str.*` | `string` | Pattern | Complex References (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [and](#and) | complex | Optional | No | Complex References (this schema) | +| [or](#or) | complex | Optional | No | Complex References (this schema) | +| [refabstract](#refabstract) | `object` | **Required** | No | Complex References (this schema) | +| [reflist](#reflist) | Simple | Optional | No | Complex References (this schema) | +| [refnamed](#refnamed) | Simple | Optional | No | Complex References (this schema) | +| [xor](#xor) | complex | Optional | No | Complex References (this schema) | +| `int.*` | `integer` | Pattern No | Complex References (this schema) | +| `str.*` | `string` | Pattern No | Complex References (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## and diff --git a/examples/docs/constants.schema.md b/examples/docs/constants.schema.md index cf4c387..fb265ef 100644 --- a/examples/docs/constants.schema.md +++ b/examples/docs/constants.schema.md @@ -17,10 +17,10 @@ This is an example schema with examples for properties with constant values # Constant Types Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [hello](#hello) | `const` | **Required** | Constant Types (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [hello](#hello) | `const` | **Required** | No | Constant Types (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## hello diff --git a/examples/docs/custom.schema.md b/examples/docs/custom.schema.md index d2971e1..fda33c9 100644 --- a/examples/docs/custom.schema.md +++ b/examples/docs/custom.schema.md @@ -17,11 +17,11 @@ This is an extensible schema. It has `definitions`, that can be used in other sc # Custom Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [bar](#bar) | `string` | Optional | Custom (this schema) | -| [foo](#foo) | `string` | Optional | Custom (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [bar](#bar) | `string` | Optional | No | Custom (this schema) | +| [foo](#foo) | `string` | Optional | No | Custom (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## bar diff --git a/examples/docs/deepextending.schema.md b/examples/docs/deepextending.schema.md index 4ec0359..b9f0a69 100644 --- a/examples/docs/deepextending.schema.md +++ b/examples/docs/deepextending.schema.md @@ -24,15 +24,15 @@ This is an extending schema. It is extending another extending schema. It pulls # Deeply Extending Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | [Definitions](definitions.schema.md#id) | -| [bar](#bar) | `string` | Optional | [Extensible](extensible.schema.md#bar) | -| [baz](#baz) | `string` | Optional | [Extending](extending.schema.md#baz) | -| [hey](#hey) | `string` | Optional | Deeply Extending (this schema) | -| [id](#id-1) | `string` | Optional | [Definitions](definitions.schema.md#id-1) | -| [meta:id](#metaid) | `string` | Optional | [Definitions](definitions.schema.md#metaid) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | [Definitions](definitions.schema.md#id) | +| [bar](#bar) | `string` | Optional | No | [Extensible](extensible.schema.md#bar) | +| [baz](#baz) | `string` | Optional | No | [Extending](extending.schema.md#baz) | +| [hey](#hey) | `string` | Optional | No | Deeply Extending (this schema) | +| [id](#id-1) | `string` | Optional | No | [Definitions](definitions.schema.md#id-1) | +| [meta:id](#metaid) | `string` | Optional | No | [Definitions](definitions.schema.md#metaid) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/examples/docs/definitions.schema.md b/examples/docs/definitions.schema.md index 0054a2e..325397f 100644 --- a/examples/docs/definitions.schema.md +++ b/examples/docs/definitions.schema.md @@ -34,12 +34,12 @@ aks. # Definitions Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | Definitions (this schema) | -| [id](#id-1) | `string` | **Required** | Definitions (this schema) | -| [meta:id](#metaid) | `string` | Optional | Definitions (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | Definitions (this schema) | +| [id](#id-1) | `string` | **Required** | No | Definitions (this schema) | +| [meta:id](#metaid) | `string` | Optional | No | Definitions (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/examples/docs/enums.schema.md b/examples/docs/enums.schema.md index 93d4716..df13056 100644 --- a/examples/docs/enums.schema.md +++ b/examples/docs/enums.schema.md @@ -17,11 +17,11 @@ This is an example schema with examples for properties with enum values # Enumerated Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [hello](#hello) | `enum` | **Required** | Enumerated (this schema) | -| [nested](#nested) | `object` | Optional | Enumerated (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [hello](#hello) | `enum` | **Required** | No | Enumerated (this schema) | +| [nested](#nested) | `object` | Optional | No | Enumerated (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## hello diff --git a/examples/docs/example.schema.md b/examples/docs/example.schema.md index 39a7d67..a17b01d 100644 --- a/examples/docs/example.schema.md +++ b/examples/docs/example.schema.md @@ -25,11 +25,11 @@ This is an example schema with examples. Too many examples? There can never be t # Example Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [bar](#bar) | `string` | Optional | Example (this schema) | -| [foo](#foo) | `string` | Optional | Example (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [bar](#bar) | `string` | Optional | No | Example (this schema) | +| [foo](#foo) | `string` | Optional | No | Example (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## bar diff --git a/examples/docs/examples.schema.md b/examples/docs/examples.schema.md index 5d4aa2c..00b8de4 100644 --- a/examples/docs/examples.schema.md +++ b/examples/docs/examples.schema.md @@ -34,11 +34,11 @@ This is an example schema with *multiple* examples. Too many examples? There can # Examples Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [bar](#bar) | `string` | **Required** | Examples (this schema) | -| [foo](#foo) | `string` | Optional | Examples (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [bar](#bar) | `string` | **Required** | No | Examples (this schema) | +| [foo](#foo) | `string` | Optional | No | Examples (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## bar diff --git a/examples/docs/extending.schema.md b/examples/docs/extending.schema.md index bc55d87..1780840 100644 --- a/examples/docs/extending.schema.md +++ b/examples/docs/extending.schema.md @@ -23,14 +23,14 @@ This is an extending schema. It pulls `definitions` from other schemas. # Extending Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | [Definitions](definitions.schema.md#id) | -| [bar](#bar) | `string` | Optional | [Extensible](extensible.schema.md#bar) | -| [baz](#baz) | `string` | Optional | Extending (this schema) | -| [id](#id-1) | `string` | Optional | [Definitions](definitions.schema.md#id-1) | -| [meta:id](#metaid) | `string` | Optional | [Definitions](definitions.schema.md#metaid) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | [Definitions](definitions.schema.md#id) | +| [bar](#bar) | `string` | Optional | No | [Extensible](extensible.schema.md#bar) | +| [baz](#baz) | `string` | Optional | No | Extending (this schema) | +| [id](#id-1) | `string` | Optional | No | [Definitions](definitions.schema.md#id-1) | +| [meta:id](#metaid) | `string` | Optional | No | [Definitions](definitions.schema.md#metaid) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/examples/docs/identifiable.schema.md b/examples/docs/identifiable.schema.md index d0dc69e..a3060fc 100644 --- a/examples/docs/identifiable.schema.md +++ b/examples/docs/identifiable.schema.md @@ -17,10 +17,10 @@ This is a *very* simple example of a JSON schema. There is only one property. # Identifiable Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | Identifiable (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | Identifiable (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/examples/docs/simple.schema.md b/examples/docs/simple.schema.md index b801c02..4d53363 100644 --- a/examples/docs/simple.schema.md +++ b/examples/docs/simple.schema.md @@ -17,10 +17,10 @@ This is a *very* simple example of a JSON schema. There is only one property. # Simple Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [id](#id) | `string` | Optional | Simple (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [id](#id) | `string` | Optional | No | Simple (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## id diff --git a/examples/docs/simpletypes.schema.md b/examples/docs/simpletypes.schema.md index b030c5a..109b836 100644 --- a/examples/docs/simpletypes.schema.md +++ b/examples/docs/simpletypes.schema.md @@ -17,26 +17,26 @@ This is an example schema with examples for multiple types and their constraints # Simple Types Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [integer_threes](#integer_threes) | `integer` | Optional | Simple Types (this schema) | -| [interger_constrained](#interger_constrained) | `integer` | Optional | Simple Types (this schema) | -| [interger_unconstrained](#interger_unconstrained) | `integer` | Optional | Simple Types (this schema) | -| [number_constrained](#number_constrained) | `number` | Optional | Simple Types (this schema) | -| [number_unconstrained](#number_unconstrained) | `number` | Optional | Simple Types (this schema) | -| [string_date](#string_date) | `string` | Optional | Simple Types (this schema) | -| [string_email](#string_email) | `string` | Optional | Simple Types (this schema) | -| [string_hostname](#string_hostname) | `string` | Optional | Simple Types (this schema) | -| [string_ipv4](#string_ipv4) | `string` | Optional | Simple Types (this schema) | -| [string_ipv6](#string_ipv6) | `string` | Optional | Simple Types (this schema) | -| [string_length](#string_length) | `string` | Optional | Simple Types (this schema) | -| [string_pattern](#string_pattern) | `string` | Optional | Simple Types (this schema) | -| [string_pattern_noexample](#string_pattern_noexample) | `string` | Optional | Simple Types (this schema) | -| [string_pattern_singleexample](#string_pattern_singleexample) | `string` | Optional | Simple Types (this schema) | -| [string_unconstrained](#string_unconstrained) | `string` | Optional | Simple Types (this schema) | -| [string_uri](#string_uri) | `string` | Optional | Simple Types (this schema) | -| [yesno](#yesno) | `boolean` | **Required** | Simple Types (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [integer_threes](#integer_threes) | `integer` | Optional | No | Simple Types (this schema) | +| [interger_constrained](#interger_constrained) | `integer` | Optional | No | Simple Types (this schema) | +| [interger_unconstrained](#interger_unconstrained) | `integer` | Optional | No | Simple Types (this schema) | +| [number_constrained](#number_constrained) | `number` | Optional | No | Simple Types (this schema) | +| [number_unconstrained](#number_unconstrained) | `number` | Optional | No | Simple Types (this schema) | +| [string_date](#string_date) | `string` | Optional | No | Simple Types (this schema) | +| [string_email](#string_email) | `string` | Optional | No | Simple Types (this schema) | +| [string_hostname](#string_hostname) | `string` | Optional | No | Simple Types (this schema) | +| [string_ipv4](#string_ipv4) | `string` | Optional | No | Simple Types (this schema) | +| [string_ipv6](#string_ipv6) | `string` | Optional | No | Simple Types (this schema) | +| [string_length](#string_length) | `string` | Optional | No | Simple Types (this schema) | +| [string_pattern](#string_pattern) | `string` | Optional | No | Simple Types (this schema) | +| [string_pattern_noexample](#string_pattern_noexample) | `string` | Optional | No | Simple Types (this schema) | +| [string_pattern_singleexample](#string_pattern_singleexample) | `string` | Optional | No | Simple Types (this schema) | +| [string_unconstrained](#string_unconstrained) | `string` | Optional | No | Simple Types (this schema) | +| [string_uri](#string_uri) | `string` | Optional | No | Simple Types (this schema) | +| [yesno](#yesno) | `boolean` | **Required** | No | Simple Types (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## integer_threes diff --git a/examples/docs/stabilizing.schema.md b/examples/docs/stabilizing.schema.md index cc1a082..c98a346 100644 --- a/examples/docs/stabilizing.schema.md +++ b/examples/docs/stabilizing.schema.md @@ -17,10 +17,10 @@ This is a schema which is currently in the `stabilizing` status. # Stabilizing Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [id](#id) | `string` | Optional | Stabilizing (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [id](#id) | `string` | Optional | No | Stabilizing (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## id diff --git a/examples/docs/typearrays.schema.md b/examples/docs/typearrays.schema.md new file mode 100644 index 0000000..a31629b --- /dev/null +++ b/examples/docs/typearrays.schema.md @@ -0,0 +1,104 @@ +--- +template: reference +foo: bar +--- + +# Type Arrays Schema + +``` +https://example.com/schemas/typearrays +``` + +This schema test type arrays and nullable types + +| [Abstract](../abstract.md) | Extensible | [Status](../status.md) | Identifiable | Custom Properties | Additional Properties | Defined In | +|----------------------------|------------|------------------------|--------------|-------------------|-----------------------|------------| +| Can be instantiated | No | Experimental | No | Forbidden | Permitted | [typearrays.schema.json](typearrays.schema.json) | + +# Type Arrays Properties + +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [null](#null) | `null` | Optional | No | Type Arrays (this schema) | +| [string-or-null](#string-or-null) | `string` | Optional | Yes | Type Arrays (this schema) | +| [string-or-number](#string-or-number) | multiple | Optional | No | Type Arrays (this schema) | +| [string-or-number-null](#string-or-number-null) | multiple | Optional | Yes | Type Arrays (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | + +## null + +This is just nothing + +`null` +* is optional +* type: `null` +* defined in this schema + +### null Type + + +`null` +This property can only have the value `null`. + + + + +## string-or-null + +Nullable string + +`string-or-null` +* is optional +* type: `string` +* defined in this schema + +### string-or-null Type + + +`string`, nullable + + + + + + +## string-or-number + +Types can be many things + +`string-or-number` +* is optional +* type: multiple +* defined in this schema + +### string-or-number Type + + +Either one of: + * `string` + * `number` + + + + + +## string-or-number-null + +Types can be many things, even nothing at all. + +`string-or-number-null` +* is optional +* type: multiple +* defined in this schema + +### string-or-number-null Type + + +Either one of: + * `string` + * `number` + * or `null` + + + + diff --git a/examples/generated-schemas/typearrays.schema.json b/examples/generated-schemas/typearrays.schema.json new file mode 100644 index 0000000..ca4fd9e --- /dev/null +++ b/examples/generated-schemas/typearrays.schema.json @@ -0,0 +1,46 @@ +{ + "meta:license": [ + "Copyright 2017 Adobe Systems Incorporated. All rights reserved.", + "This file is licensed to you under the Apache License, Version 2.0 (the 'License');", + "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" + ], + "$schema": "http://json-schema.org/draft-06/schema#", + "$id": "https://example.com/schemas/typearrays", + "title": "Type Arrays", + "description": "This schema test type arrays and nullable types", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/id" + } + ], + "properties": { + "null": { + "type": "null", + "description": "This is just nothing" + }, + "string-or-null": { + "type": [ + "string", + "null" + ], + "description": "Nullable string" + }, + "string-or-number": { + "type": [ + "string", + "number" + ], + "description": "Types can be many things" + }, + "string-or-number-null": { + "type": [ + "string", + "number", + "null" + ], + "description": "Types can be many things, even nothing at all." + } + } +} \ No newline at end of file diff --git a/examples/schemas/typearrays.schema.json b/examples/schemas/typearrays.schema.json new file mode 100644 index 0000000..60438f0 --- /dev/null +++ b/examples/schemas/typearrays.schema.json @@ -0,0 +1,36 @@ +{ + "meta:license": [ + "Copyright 2017 Adobe Systems Incorporated. All rights reserved.", + "This file is licensed to you under the Apache License, Version 2.0 (the 'License');", + "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" + ], + "$schema": "http://json-schema.org/draft-06/schema#", + "$id": "https://example.com/schemas/typearrays", + "title": "Type Arrays", + "description": "This schema test type arrays and nullable types", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/id" + } + ], + "properties": { + "null": { + "type": "null", + "description": "This is just nothing" + }, + "string-or-null": { + "type": ["string", "null"], + "description": "Nullable string" + }, + "string-or-number": { + "type": ["string", "number"], + "description": "Types can be many things" + }, + "string-or-number-null": { + "type": ["string", "number", "null"], + "description": "Types can be many things, even nothing at all." + } + } +} \ No newline at end of file diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index 018a5dc..1a2b571 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -103,6 +103,8 @@ function simpletype(prop) { prop.simpletype = '`integer`'; } else if (type==='object') { prop.simpletype = '`object`'; + } else if (type==='null') { + prop.simpletype = '`null`'; } else if (type==='array') { if (prop.items!==undefined) { const innertype = simpletype(prop.items); @@ -115,6 +117,21 @@ function simpletype(prop) { } else { prop.simpletype = '`array`'; } + } else if (Array.isArray(type)) { + function nullfilter(str) { + return str!=='null'; + } + var filtered = type.filter(nullfilter); + if (type.length - 1 === filtered.length) { + prop.nullable = true; + } + if (filtered.length===1) { + prop.type = filtered[0]; + prop.simpletype = '`' + filtered[0] + '`'; + } else { + prop.type = filtered; + prop.simpletype = 'multiple'; + } } else { prop.simpletype = 'complex'; } diff --git a/spec/examples/README.md b/spec/examples/README.md index cbf8be8..f6545c1 100644 --- a/spec/examples/README.md +++ b/spec/examples/README.md @@ -22,6 +22,7 @@ * [Simple](./simple.schema.md) – `https://example.com/schemas/simple` (Unknown) * [Simple Types](./simpletypes.schema.md) – `https://example.com/schemas/simpletypes` (Unknown) * [Stabilizing](./stabilizing.schema.md) – `https://example.com/schemas/stabilizing` (Stabilizing) +* [Type Arrays](./typearrays.schema.md) – `https://example.com/schemas/typearrays` (Unknown) ## /subdir/ diff --git a/spec/examples/arrays.schema.md b/spec/examples/arrays.schema.md index 74c7371..4ed3a03 100644 --- a/spec/examples/arrays.schema.md +++ b/spec/examples/arrays.schema.md @@ -17,17 +17,17 @@ This is an example schema with examples for multiple array types and their const # Arrays Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [boollist](#boollist) | `boolean[]` | Optional | Arrays (this schema) | -| [coordinatelist](#coordinatelist) | `number[][]` | Optional | Arrays (this schema) | -| [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) | -| [list](#list) | `string[]` | Optional | Arrays (this schema) | -| [listlist](#listlist) | `array[]` | Optional | Arrays (this schema) | -| [numlist](#numlist) | `number[]` | Optional | Arrays (this schema) | -| [objectlist](#objectlist) | `object[]` | Optional | Arrays (this schema) | -| [stringlistlist](#stringlistlist) | `string[][]` | Optional | Arrays (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [boollist](#boollist) | `boolean[]` | Optional | No | Arrays (this schema) | +| [coordinatelist](#coordinatelist) | `number[][]` | Optional | No | Arrays (this schema) | +| [intlist](#intlist) | `integer[]` | Optional | No | Arrays (this schema) | +| [list](#list) | `string[]` | Optional | No | Arrays (this schema) | +| [listlist](#listlist) | `array[]` | Optional | No | Arrays (this schema) | +| [numlist](#numlist) | `number[]` | Optional | No | Arrays (this schema) | +| [objectlist](#objectlist) | `object[]` | Optional | No | Arrays (this schema) | +| [stringlistlist](#stringlistlist) | `string[][]` | Optional | No | Arrays (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## boollist diff --git a/spec/examples/complex.schema.md b/spec/examples/complex.schema.md index c813c30..d1faebd 100644 --- a/spec/examples/complex.schema.md +++ b/spec/examples/complex.schema.md @@ -23,17 +23,17 @@ This is an example schema that uses types defined in other schemas. # Complex References Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [and](#and) | complex | Optional | Complex References (this schema) | -| [or](#or) | complex | Optional | Complex References (this schema) | -| [refabstract](#refabstract) | `object` | **Required** | Complex References (this schema) | -| [reflist](#reflist) | Simple | Optional | Complex References (this schema) | -| [refnamed](#refnamed) | Simple | Optional | Complex References (this schema) | -| [xor](#xor) | complex | Optional | Complex References (this schema) | -| `int.*` | `integer` | Pattern | Complex References (this schema) | -| `str.*` | `string` | Pattern | Complex References (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [and](#and) | complex | Optional | No | Complex References (this schema) | +| [or](#or) | complex | Optional | No | Complex References (this schema) | +| [refabstract](#refabstract) | `object` | **Required** | No | Complex References (this schema) | +| [reflist](#reflist) | Simple | Optional | No | Complex References (this schema) | +| [refnamed](#refnamed) | Simple | Optional | No | Complex References (this schema) | +| [xor](#xor) | complex | Optional | No | Complex References (this schema) | +| `int.*` | `integer` | Pattern No | Complex References (this schema) | +| `str.*` | `string` | Pattern No | Complex References (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## and diff --git a/spec/examples/constants.schema.md b/spec/examples/constants.schema.md index cf4c387..fb265ef 100644 --- a/spec/examples/constants.schema.md +++ b/spec/examples/constants.schema.md @@ -17,10 +17,10 @@ This is an example schema with examples for properties with constant values # Constant Types Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [hello](#hello) | `const` | **Required** | Constant Types (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [hello](#hello) | `const` | **Required** | No | Constant Types (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## hello diff --git a/spec/examples/custom.schema.md b/spec/examples/custom.schema.md index d2971e1..fda33c9 100644 --- a/spec/examples/custom.schema.md +++ b/spec/examples/custom.schema.md @@ -17,11 +17,11 @@ This is an extensible schema. It has `definitions`, that can be used in other sc # Custom Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [bar](#bar) | `string` | Optional | Custom (this schema) | -| [foo](#foo) | `string` | Optional | Custom (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [bar](#bar) | `string` | Optional | No | Custom (this schema) | +| [foo](#foo) | `string` | Optional | No | Custom (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## bar diff --git a/spec/examples/deepextending.schema.md b/spec/examples/deepextending.schema.md index 4ec0359..b9f0a69 100644 --- a/spec/examples/deepextending.schema.md +++ b/spec/examples/deepextending.schema.md @@ -24,15 +24,15 @@ This is an extending schema. It is extending another extending schema. It pulls # Deeply Extending Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | [Definitions](definitions.schema.md#id) | -| [bar](#bar) | `string` | Optional | [Extensible](extensible.schema.md#bar) | -| [baz](#baz) | `string` | Optional | [Extending](extending.schema.md#baz) | -| [hey](#hey) | `string` | Optional | Deeply Extending (this schema) | -| [id](#id-1) | `string` | Optional | [Definitions](definitions.schema.md#id-1) | -| [meta:id](#metaid) | `string` | Optional | [Definitions](definitions.schema.md#metaid) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | [Definitions](definitions.schema.md#id) | +| [bar](#bar) | `string` | Optional | No | [Extensible](extensible.schema.md#bar) | +| [baz](#baz) | `string` | Optional | No | [Extending](extending.schema.md#baz) | +| [hey](#hey) | `string` | Optional | No | Deeply Extending (this schema) | +| [id](#id-1) | `string` | Optional | No | [Definitions](definitions.schema.md#id-1) | +| [meta:id](#metaid) | `string` | Optional | No | [Definitions](definitions.schema.md#metaid) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/spec/examples/definitions.schema.md b/spec/examples/definitions.schema.md index 0054a2e..325397f 100644 --- a/spec/examples/definitions.schema.md +++ b/spec/examples/definitions.schema.md @@ -34,12 +34,12 @@ aks. # Definitions Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | Definitions (this schema) | -| [id](#id-1) | `string` | **Required** | Definitions (this schema) | -| [meta:id](#metaid) | `string` | Optional | Definitions (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | Definitions (this schema) | +| [id](#id-1) | `string` | **Required** | No | Definitions (this schema) | +| [meta:id](#metaid) | `string` | Optional | No | Definitions (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/spec/examples/enums.schema.md b/spec/examples/enums.schema.md index 93d4716..df13056 100644 --- a/spec/examples/enums.schema.md +++ b/spec/examples/enums.schema.md @@ -17,11 +17,11 @@ This is an example schema with examples for properties with enum values # Enumerated Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [hello](#hello) | `enum` | **Required** | Enumerated (this schema) | -| [nested](#nested) | `object` | Optional | Enumerated (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [hello](#hello) | `enum` | **Required** | No | Enumerated (this schema) | +| [nested](#nested) | `object` | Optional | No | Enumerated (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## hello diff --git a/spec/examples/example.schema.md b/spec/examples/example.schema.md index 39a7d67..a17b01d 100644 --- a/spec/examples/example.schema.md +++ b/spec/examples/example.schema.md @@ -25,11 +25,11 @@ This is an example schema with examples. Too many examples? There can never be t # Example Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [bar](#bar) | `string` | Optional | Example (this schema) | -| [foo](#foo) | `string` | Optional | Example (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [bar](#bar) | `string` | Optional | No | Example (this schema) | +| [foo](#foo) | `string` | Optional | No | Example (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## bar diff --git a/spec/examples/examples.schema.md b/spec/examples/examples.schema.md index 5d4aa2c..00b8de4 100644 --- a/spec/examples/examples.schema.md +++ b/spec/examples/examples.schema.md @@ -34,11 +34,11 @@ This is an example schema with *multiple* examples. Too many examples? There can # Examples Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [bar](#bar) | `string` | **Required** | Examples (this schema) | -| [foo](#foo) | `string` | Optional | Examples (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [bar](#bar) | `string` | **Required** | No | Examples (this schema) | +| [foo](#foo) | `string` | Optional | No | Examples (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## bar diff --git a/spec/examples/extending.schema.md b/spec/examples/extending.schema.md index bc55d87..1780840 100644 --- a/spec/examples/extending.schema.md +++ b/spec/examples/extending.schema.md @@ -23,14 +23,14 @@ This is an extending schema. It pulls `definitions` from other schemas. # Extending Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | [Definitions](definitions.schema.md#id) | -| [bar](#bar) | `string` | Optional | [Extensible](extensible.schema.md#bar) | -| [baz](#baz) | `string` | Optional | Extending (this schema) | -| [id](#id-1) | `string` | Optional | [Definitions](definitions.schema.md#id-1) | -| [meta:id](#metaid) | `string` | Optional | [Definitions](definitions.schema.md#metaid) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | [Definitions](definitions.schema.md#id) | +| [bar](#bar) | `string` | Optional | No | [Extensible](extensible.schema.md#bar) | +| [baz](#baz) | `string` | Optional | No | Extending (this schema) | +| [id](#id-1) | `string` | Optional | No | [Definitions](definitions.schema.md#id-1) | +| [meta:id](#metaid) | `string` | Optional | No | [Definitions](definitions.schema.md#metaid) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/spec/examples/identifiable.schema.md b/spec/examples/identifiable.schema.md index d0dc69e..a3060fc 100644 --- a/spec/examples/identifiable.schema.md +++ b/spec/examples/identifiable.schema.md @@ -17,10 +17,10 @@ This is a *very* simple example of a JSON schema. There is only one property. # Identifiable Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [@id](#id) | `string` | Optional | Identifiable (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [@id](#id) | `string` | Optional | No | Identifiable (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## @id diff --git a/spec/examples/simple.schema.md b/spec/examples/simple.schema.md index b801c02..4d53363 100644 --- a/spec/examples/simple.schema.md +++ b/spec/examples/simple.schema.md @@ -17,10 +17,10 @@ This is a *very* simple example of a JSON schema. There is only one property. # Simple Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [id](#id) | `string` | Optional | Simple (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [id](#id) | `string` | Optional | No | Simple (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## id diff --git a/spec/examples/simpletypes.schema.md b/spec/examples/simpletypes.schema.md index b030c5a..109b836 100644 --- a/spec/examples/simpletypes.schema.md +++ b/spec/examples/simpletypes.schema.md @@ -17,26 +17,26 @@ This is an example schema with examples for multiple types and their constraints # Simple Types Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [integer_threes](#integer_threes) | `integer` | Optional | Simple Types (this schema) | -| [interger_constrained](#interger_constrained) | `integer` | Optional | Simple Types (this schema) | -| [interger_unconstrained](#interger_unconstrained) | `integer` | Optional | Simple Types (this schema) | -| [number_constrained](#number_constrained) | `number` | Optional | Simple Types (this schema) | -| [number_unconstrained](#number_unconstrained) | `number` | Optional | Simple Types (this schema) | -| [string_date](#string_date) | `string` | Optional | Simple Types (this schema) | -| [string_email](#string_email) | `string` | Optional | Simple Types (this schema) | -| [string_hostname](#string_hostname) | `string` | Optional | Simple Types (this schema) | -| [string_ipv4](#string_ipv4) | `string` | Optional | Simple Types (this schema) | -| [string_ipv6](#string_ipv6) | `string` | Optional | Simple Types (this schema) | -| [string_length](#string_length) | `string` | Optional | Simple Types (this schema) | -| [string_pattern](#string_pattern) | `string` | Optional | Simple Types (this schema) | -| [string_pattern_noexample](#string_pattern_noexample) | `string` | Optional | Simple Types (this schema) | -| [string_pattern_singleexample](#string_pattern_singleexample) | `string` | Optional | Simple Types (this schema) | -| [string_unconstrained](#string_unconstrained) | `string` | Optional | Simple Types (this schema) | -| [string_uri](#string_uri) | `string` | Optional | Simple Types (this schema) | -| [yesno](#yesno) | `boolean` | **Required** | Simple Types (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [integer_threes](#integer_threes) | `integer` | Optional | No | Simple Types (this schema) | +| [interger_constrained](#interger_constrained) | `integer` | Optional | No | Simple Types (this schema) | +| [interger_unconstrained](#interger_unconstrained) | `integer` | Optional | No | Simple Types (this schema) | +| [number_constrained](#number_constrained) | `number` | Optional | No | Simple Types (this schema) | +| [number_unconstrained](#number_unconstrained) | `number` | Optional | No | Simple Types (this schema) | +| [string_date](#string_date) | `string` | Optional | No | Simple Types (this schema) | +| [string_email](#string_email) | `string` | Optional | No | Simple Types (this schema) | +| [string_hostname](#string_hostname) | `string` | Optional | No | Simple Types (this schema) | +| [string_ipv4](#string_ipv4) | `string` | Optional | No | Simple Types (this schema) | +| [string_ipv6](#string_ipv6) | `string` | Optional | No | Simple Types (this schema) | +| [string_length](#string_length) | `string` | Optional | No | Simple Types (this schema) | +| [string_pattern](#string_pattern) | `string` | Optional | No | Simple Types (this schema) | +| [string_pattern_noexample](#string_pattern_noexample) | `string` | Optional | No | Simple Types (this schema) | +| [string_pattern_singleexample](#string_pattern_singleexample) | `string` | Optional | No | Simple Types (this schema) | +| [string_unconstrained](#string_unconstrained) | `string` | Optional | No | Simple Types (this schema) | +| [string_uri](#string_uri) | `string` | Optional | No | Simple Types (this schema) | +| [yesno](#yesno) | `boolean` | **Required** | No | Simple Types (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## integer_threes diff --git a/spec/examples/stabilizing.schema.md b/spec/examples/stabilizing.schema.md index cc1a082..c98a346 100644 --- a/spec/examples/stabilizing.schema.md +++ b/spec/examples/stabilizing.schema.md @@ -17,10 +17,10 @@ This is a schema which is currently in the `stabilizing` status. # Stabilizing Properties -| Property | Type | Required | Defined by | -|----------|------|----------|------------| -| [id](#id) | `string` | Optional | Stabilizing (this schema) | -| `*` | any | Additional | this schema *allows* additional properties | +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [id](#id) | `string` | Optional | No | Stabilizing (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | ## id diff --git a/spec/examples/typearrays.schema.md b/spec/examples/typearrays.schema.md new file mode 100644 index 0000000..a31629b --- /dev/null +++ b/spec/examples/typearrays.schema.md @@ -0,0 +1,104 @@ +--- +template: reference +foo: bar +--- + +# Type Arrays Schema + +``` +https://example.com/schemas/typearrays +``` + +This schema test type arrays and nullable types + +| [Abstract](../abstract.md) | Extensible | [Status](../status.md) | Identifiable | Custom Properties | Additional Properties | Defined In | +|----------------------------|------------|------------------------|--------------|-------------------|-----------------------|------------| +| Can be instantiated | No | Experimental | No | Forbidden | Permitted | [typearrays.schema.json](typearrays.schema.json) | + +# Type Arrays Properties + +| Property | Type | Required | Nullable | Defined by | +|----------|------|----------|----------|------------| +| [null](#null) | `null` | Optional | No | Type Arrays (this schema) | +| [string-or-null](#string-or-null) | `string` | Optional | Yes | Type Arrays (this schema) | +| [string-or-number](#string-or-number) | multiple | Optional | No | Type Arrays (this schema) | +| [string-or-number-null](#string-or-number-null) | multiple | Optional | Yes | Type Arrays (this schema) | +| `*` | any | Additional | Yes | this schema *allows* additional properties | + +## null + +This is just nothing + +`null` +* is optional +* type: `null` +* defined in this schema + +### null Type + + +`null` +This property can only have the value `null`. + + + + +## string-or-null + +Nullable string + +`string-or-null` +* is optional +* type: `string` +* defined in this schema + +### string-or-null Type + + +`string`, nullable + + + + + + +## string-or-number + +Types can be many things + +`string-or-number` +* is optional +* type: multiple +* defined in this schema + +### string-or-number Type + + +Either one of: + * `string` + * `number` + + + + + +## string-or-number-null + +Types can be many things, even nothing at all. + +`string-or-number-null` +* is optional +* type: multiple +* defined in this schema + +### string-or-number-null Type + + +Either one of: + * `string` + * `number` + * or `null` + + + + diff --git a/spec/lib/integrationTest.spec.js b/spec/lib/integrationTest.spec.js index ae86bfb..5107d18 100644 --- a/spec/lib/integrationTest.spec.js +++ b/spec/lib/integrationTest.spec.js @@ -54,7 +54,7 @@ describe('Compare results', () => { ls.on('close', code => { expect(code).toEqual(0); const files = readdirSync('./spec/examples').filter(item => !(/(^|\/)\.[^\/\.]/g).test(item)); - expect(files.length).toEqual(18); + expect(files.length).toEqual(19); done(); }); }); diff --git a/templates/md/boolean-type.ejs b/templates/md/boolean-type.ejs index a5789ce..85a9b07 100644 --- a/templates/md/boolean-type.ejs +++ b/templates/md/boolean-type.ejs @@ -5,4 +5,4 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -`<%=schema.type %>` +`<%=schema.type %>`<%=schema.nullable ? ", nullable" : "" %> diff --git a/templates/md/multiple-type.ejs b/templates/md/multiple-type.ejs new file mode 100644 index 0000000..57accdf --- /dev/null +++ b/templates/md/multiple-type.ejs @@ -0,0 +1,13 @@ +<% /** + * Copyright 2018 Adobe Systems Incorporated. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * 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 + */ %> + +Either one of: +<% _.forEach(schema.type, (t) => { %> + * `<%= t %>` +<% }); %><% if (schema.nullable) { %> + * or `null` +<% } %> \ No newline at end of file diff --git a/templates/md/null-type.ejs b/templates/md/null-type.ejs new file mode 100644 index 0000000..f65aa15 --- /dev/null +++ b/templates/md/null-type.ejs @@ -0,0 +1,10 @@ +<% /** + * Copyright 2018 Adobe Systems Incorporated. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * 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 + */ %> + +`null` + +This property can only have the value `null`. \ No newline at end of file diff --git a/templates/md/number-type.ejs b/templates/md/number-type.ejs index 6f32d87..e5953bf 100644 --- a/templates/md/number-type.ejs +++ b/templates/md/number-type.ejs @@ -5,7 +5,7 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -`<%=schema.type %>` +`<%=schema.type %>`<%=schema.nullable ? ", nullable" : "" %> <% if(schema.exclusiveMinumum!==undefined) { %>* value must not be smaller or equal than: `<%=schema.exclusiveMinumum %>`<% } else if(schema.minimum!==undefined) { diff --git a/templates/md/object-type.ejs b/templates/md/object-type.ejs index 12b7462..7b79942 100644 --- a/templates/md/object-type.ejs +++ b/templates/md/object-type.ejs @@ -5,7 +5,7 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -`object` with following properties: +`object`<%=schema.nullable ? ", nullable," : "" %> with following properties: <%- include("nested-properties",{outer:schema,props: schema.properties,_:_, nested:true}) %> diff --git a/templates/md/properties.ejs b/templates/md/properties.ejs index 583301d..238928f 100644 --- a/templates/md/properties.ejs +++ b/templates/md/properties.ejs @@ -8,11 +8,11 @@ <% const hasDefault = _.keys(props).filter(property => _.has(props, property + '.default')).length > 0; %> -| Property | Type | Required |<% if(hasDefault) { %> Default |<% } %> Defined by | -|----------|------|----------|<% if(hasDefault) { %>---------|<% } %>------------| +| Property | Type | Required | Nullable |<% if(hasDefault) { %> Default |<% } %> Defined by | +|----------|------|----------|----------|<% if(hasDefault) { %>---------|<% } %>------------| <% _.keys(props).sort().forEach(property => { const schema = props[property]; %> -| [<%= property %>](#<%= propertiesSlugs[property] %>) | <%= schema.simpletype %> | <%= schema.isrequired === true ? "**Required**" : "Optional" %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% +| [<%= property %>](#<%= propertiesSlugs[property] %>) | <%= schema.simpletype %> | <%= schema.isrequired === true ? "**Required**" : "Optional" %> | <%= schema.nullable === true ? "Yes" : "No" %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= propertiesSlugs[property] %>)<% } else { @@ -21,7 +21,7 @@ }); %><% _.keys(pprops).forEach(property => { const schema = pprops[property]; %> -| `<%= property.replace(':', '') %>` | <%= schema.simpletype %> | Pattern |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% +| `<%= property.replace(':', '') %>` | <%= schema.simpletype %> | Pattern <%= schema.nullable === true ? "Yes" : "No" %> |<% if(hasDefault) { %> <% if (schema.default!==undefined) { %>`<%- JSON.stringify(schema.default) %>`<% } %> |<% } %> <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= property.replace(':', '').toLowerCase() %>)<% } else { @@ -29,5 +29,5 @@ <% }); %><% if (additional!==false||additional===undefined) { %> -| `*` | any | Additional | this schema *allows* additional properties | +| `*` | any | Additional | Yes | this schema *allows* additional properties | <% } %> \ No newline at end of file diff --git a/templates/md/property.ejs b/templates/md/property.ejs index 0c2b733..17aef7c 100644 --- a/templates/md/property.ejs +++ b/templates/md/property.ejs @@ -41,6 +41,8 @@ The value of this property **must** be equal to one of the [known values below]( <%- include("string-type",{schema:schema,_:_}) %> <% } else if (schema.type==="number"||schema.type==="integer") { %> <%- include("number-type",{schema:schema,_:_}) %> +<% } else if (schema.type==="null") { %> +<%- include("null-type",{schema:schema,_:_}) %> <% } else if (schema.type==="boolean") { %> <%- include("boolean-type",{schema:schema,_:_}) %> <% } else if (schema.type==="object") { %> @@ -51,6 +53,8 @@ The value of this property **must** be equal to one of the [known values below]( <%- include("referenced-type",{schema:schema,_:_}) %> <% } else if (schema.anyOf!==undefined || schema.allOf!==undefined || schema.oneOf!==undefined) { %> <%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs}) %> +<% } else if (schema.simpletype==="multiple") { %> +<%- include("multiple-type",{schema:schema,_:_}) %> <% } else { %> Unknown type `<%= schema.type %>`. diff --git a/templates/md/string-type.ejs b/templates/md/string-type.ejs index 72e686e..0713c93 100644 --- a/templates/md/string-type.ejs +++ b/templates/md/string-type.ejs @@ -5,7 +5,7 @@ * of the License at http://www.apache.org/licenses/LICENSE-2.0 */ %> -`string` +`string`<%=schema.nullable ? ", nullable" : "" %> <% if (schema.format==="uri") { %>* format: `uri` – Uniformous Resource Identifier (according to [RFC3986](http://tools.ietf.org/html/rfc3986))<% } else if (schema.format==="date-time") { %>* format: `date-time` – date and time (according to [RFC 3339, section 5.6](http://tools.ietf.org/html/rfc3339))<% } -- GitLab