diff --git a/examples/docs/README.md b/examples/docs/README.md index 3d8ad58703bde17e2f6edcdcd234edf39b25cacf..264fafca73d6a2dca5de2ee870baaba6df4e67d6 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -15,6 +15,7 @@ * [Extending](./extending.schema.md) – `https://example.com/schemas/extending` * [Extensible](./extensible.schema.md) – `https://example.com/schemas/extensible` * [Simple](./simple.schema.md) – `https://example.com/schemas/simple` +* [Simple Types](./simpletypes.schema.md) – `https://example.com/schemas/simpletypes` ## /subdir/ diff --git a/examples/docs/custom.schema.md b/examples/docs/custom.schema.md index 753f3ec3fae4128f445b16e0f227c64f52dba4e8..1119cd37bb98e369c7c1ee4a306530f499bfdde6 100644 --- a/examples/docs/custom.schema.md +++ b/examples/docs/custom.schema.md @@ -31,7 +31,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in this schema -### Type +### foo Type + +This is a string. ### Known Values @@ -51,7 +53,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in this schema -### Type +### bar Type + +This is a string. ### Known Values diff --git a/examples/docs/deepextending.schema.md b/examples/docs/deepextending.schema.md index 50b93c5af751b3c9af2fccfa11e0674e5f160c28..fb695e34baf1f3c800518224aaf7b576bbb4c7ea 100644 --- a/examples/docs/deepextending.schema.md +++ b/examples/docs/deepextending.schema.md @@ -40,7 +40,9 @@ A horse walks into it. * type: `string` * defined in [Extensible](extensible.schema.md#bar) -### Type +### bar Type + +This is a string. ### Known Values @@ -70,7 +72,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in [Definitions](definitions.schema.md#id) -### Type +### id Type + +This is a string. ### Known Values @@ -91,7 +95,9 @@ This property has a unique name to demonstrate it's uniqueness. * type: `string` * defined in [Extending](extending.schema.md#baz) -### Type +### baz Type + +This is a string. ### Known Values @@ -116,7 +122,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in this schema -### Type +### hey Type + +This is a string. ### Known Values diff --git a/examples/docs/definitions.schema.md b/examples/docs/definitions.schema.md index e304bf386e9e0737c4ae98f599de76052d546f56..33fb63576d130047e76e668df5709f301cb3622b 100644 --- a/examples/docs/definitions.schema.md +++ b/examples/docs/definitions.schema.md @@ -31,7 +31,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in this schema -### Type +### id Type + +This is a string. ### Known Values diff --git a/examples/docs/example.schema.md b/examples/docs/example.schema.md index 6b3e6eb55bc7a71d8e90345aa1a85b156d0d29ae..ab15172740b5f9ff74becdb0b77ecca1f552e3d4 100644 --- a/examples/docs/example.schema.md +++ b/examples/docs/example.schema.md @@ -17,7 +17,10 @@ This is an example schema with examples. Too many examples? There can never be t ## Example Example ```json -{"foo":"bar","bar":"baz"} +{ + "foo": "bar", + "bar": "baz" +} ``` # Example Properties @@ -36,7 +39,9 @@ A simple string. * type: `string` * defined in this schema -### Type +### foo Type + +This is a string. ### Known Values @@ -61,7 +66,9 @@ A simple string. * type: `string` * defined in this schema -### Type +### bar Type + +This is a string. ### Known Values diff --git a/examples/docs/examples.schema.md b/examples/docs/examples.schema.md index ac79b3e2bcfb3c1a5e8e5a7ca567a93abb8e98e3..b12b7210d6dc1a90d8de5e40a501891881a02f0b 100644 --- a/examples/docs/examples.schema.md +++ b/examples/docs/examples.schema.md @@ -18,11 +18,17 @@ This is an example schema with *multiple* examples. Too many examples? There can ## Examples Examples ```json -{"foo":"bi","bar":"bu"} +{ + "foo": "bi", + "bar": "bu" +} ``` ```json -{"foo":"zip","bar":"zap"} +{ + "foo": "zip", + "bar": "zap" +} ``` @@ -42,7 +48,9 @@ A simple string. * type: `string` * defined in this schema -### Type +### foo Type + +This is a string. ### Known Values @@ -67,7 +75,9 @@ A simple string. * type: `string` * defined in this schema -### Type +### bar Type + +This is a string. ### Known Values diff --git a/examples/docs/extending.schema.md b/examples/docs/extending.schema.md index d1eb774001a973d5e77ef34652ee2642e3a873d3..ed20f917651fcd735fe88478c1c54c7de178ae4e 100644 --- a/examples/docs/extending.schema.md +++ b/examples/docs/extending.schema.md @@ -38,7 +38,9 @@ A horse walks into it. * type: `string` * defined in [Extensible](extensible.schema.md#bar) -### Type +### bar Type + +This is a string. ### Known Values @@ -68,7 +70,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in [Definitions](definitions.schema.md#id) -### Type +### id Type + +This is a string. ### Known Values @@ -89,7 +93,9 @@ This property has a unique name to demonstrate it's uniqueness. * type: `string` * defined in this schema -### Type +### baz Type + +This is a string. ### Known Values diff --git a/examples/docs/simple.schema.md b/examples/docs/simple.schema.md index 64e9d7906b67aa582a87e82bc8213a78d29cd214..9e7734cf0b9a0f98815dfc2199217d6537bbe701 100644 --- a/examples/docs/simple.schema.md +++ b/examples/docs/simple.schema.md @@ -30,7 +30,9 @@ A unique identifier given to every addressable thing. * type: `string` * defined in this schema -### Type +### id Type + +This is a string. ### Known Values diff --git a/examples/docs/simpletypes.schema.md b/examples/docs/simpletypes.schema.md new file mode 100644 index 0000000000000000000000000000000000000000..5653fac74a6806f00f8abd72d9aec203fc7fc7d6 --- /dev/null +++ b/examples/docs/simpletypes.schema.md @@ -0,0 +1,274 @@ +--- +template: reference +foo: bar +--- + +# Simple Types Schema + +``` +https://example.com/schemas/simpletypes +``` + +This is an example schema with examples for multiple types and their constraints. + +| Abstract | Extensible | Custom Properties | Defined In | +|----------|------------|-------------------|------------| +| Can be instantiated | No | Forbidden | [simpletypes.schema.json](simpletypes.schema.json) | + +# Simple Types Properties + +| Property | Type | Required | Defined by | +|----------|------|----------|------------| +| [string_unconstrained](#string_unconstrained) | `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_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_uri](#string_uri) | `string` | Optional | Simple Types (this schema) | +| [number_unconstrained](#number_unconstrained) | `number` | Optional | Simple Types (this schema) | + +## string_unconstrained + +A simple string, without any constraints. + +`string_unconstrained` +* is optional +* type: `string` +* defined in this schema + +### string_unconstrained Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + +### string_unconstrained Example + +```json +"bar" +``` + + +## string_length + +A string with minumum and maximum length + +`string_length` +* is optional +* type: `string` +* defined in this schema + +### string_length Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + +### string_length Examples + +```json +"bar" +``` + +```json +"baz" +``` + + + +## string_pattern + +A string following a regular expression + +`string_pattern` +* is optional +* type: `string` +* defined in this schema + +### string_pattern Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## string_date + +A date-like string. + +`string_date` +* is optional +* type: `string` +* defined in this schema + +### string_date Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## string_email + +An email-like string. + +`string_email` +* is optional +* type: `string` +* defined in this schema + +### string_email Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## string_hostname + +A hostname-like string. + +`string_hostname` +* is optional +* type: `string` +* defined in this schema + +### string_hostname Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## string_ipv4 + +An IPv4-like string. + +`string_ipv4` +* is optional +* type: `string` +* defined in this schema + +### string_ipv4 Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## string_ipv6 + +An IPv6-like string. + +`string_ipv6` +* is optional +* type: `string` +* defined in this schema + +### string_ipv6 Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## string_uri + +A URI. + +`string_uri` +* is optional +* type: `string` +* defined in this schema + +### string_uri Type + +This is a string. + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + + +## number_unconstrained + +Just a number + +`number_unconstrained` +* is optional +* type: `number` +* defined in this schema + +### number_unconstrained Type + +Unknown type `number`. + +```json +{ + "type": "number", + "description": "Just a number", + "simpletype": "`number`" +} +``` + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + diff --git a/examples/generated-schemas/simpletypes.schema.json b/examples/generated-schemas/simpletypes.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..e7ea5e13f9093c900b6647c7440c15349c0d9f6c --- /dev/null +++ b/examples/generated-schemas/simpletypes.schema.json @@ -0,0 +1,72 @@ +{ + "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/simpletypes", + "title": "Simple Types", + "type": "object", + "description": "This is an example schema with examples for multiple types and their constraints.", + "properties": { + "string_unconstrained": { + "type": "string", + "description": "A simple string, without any constraints.", + "meta:example": "bar" + }, + "string_length": { + "type": "string", + "description": "A string with minumum and maximum length", + "meta:example": [ + "bar", + "baz" + ], + "minLength": 3, + "maxLength": 3 + }, + "string_pattern": { + "type": "string", + "description": "A string following a regular expression", + "pattern": "^ba.$" + }, + "string_date": { + "type": "string", + "description": "A date-like string.", + "format": "date-time" + }, + "string_email": { + "type": "string", + "description": "An email-like string.", + "format": "email" + }, + "string_hostname": { + "type": "string", + "description": "A hostname-like string.", + "format": "hostname" + }, + "string_ipv4": { + "type": "string", + "description": "An IPv4-like string.", + "format": "ipv4" + }, + "string_ipv6": { + "type": "string", + "description": "An IPv6-like string.", + "format": "ipv6" + }, + "string_uri": { + "type": "string", + "description": "A URI.", + "format": "uri" + }, + "number_unconstrained": { + "type": "number", + "description": "Just a number" + } + }, + "required": [ + "bar" + ] +} \ No newline at end of file diff --git a/examples/schemas/simpletypes.schema.json b/examples/schemas/simpletypes.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..3f0cc8efa29e7bbbc3214540dc6ab4a2fa2f7054 --- /dev/null +++ b/examples/schemas/simpletypes.schema.json @@ -0,0 +1,69 @@ +{ + "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/simpletypes", + "title": "Simple Types", + "type": "object", + "description": "This is an example schema with examples for multiple types and their constraints.", + "properties": { + "string_unconstrained": { + "type": "string", + "description": "A simple string, without any constraints.", + "meta:example": "bar" + }, + "string_length": { + "type": "string", + "description": "A string with minumum and maximum length", + "meta:example": ["bar", "baz"], + "minLength": 3, + "maxLength": 3 + }, + "string_pattern": { + "type": "string", + "description": "A string following a regular expression", + "pattern": "^ba.$" + }, + "string_date": { + "type": "string", + "description": "A date-like string.", + "format": "date-time" + }, + "string_email": { + "type": "string", + "description": "An email-like string.", + "format": "email" + }, + "string_hostname": { + "type": "string", + "description": "A hostname-like string.", + "format": "hostname" + }, + "string_ipv4": { + "type": "string", + "description": "An IPv4-like string.", + "format": "ipv4" + }, + "string_ipv6": { + "type": "string", + "description": "An IPv6-like string.", + "format": "ipv6" + }, + "string_uri": { + "type": "string", + "description": "A URI.", + "format": "uri" + }, + "number_unconstrained": { + "type": "number", + "description": "Just a number" + } + }, + "required": [ + "bar" + ] +} diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index ad095b6b746b3614b5018e9cc871304663283a26..26b53fb84825786211ce0038956dc15562e17d8b 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -69,7 +69,7 @@ function stringifyExamples(examples) { } console.log(examples); return examples.map(example => { - return JSON.stringify(example, 2); + return JSON.stringify(example, null, 2); }); } else { return false; @@ -97,7 +97,9 @@ function simpletype(prop) { function requiredProperties(properties, required) { if (required) { for (let i=0;i<required.length;i++) { - properties[required[i]].required = true; + if (properties[required[i]]) { + properties[required[i]].required = true; + } } } return _.mapValues(properties, simpletype); diff --git a/templates/md/property.ejs b/templates/md/property.ejs index 866c05e63b0e583d8887de653f8831653638b068..05a1f20c49065c599f4dbc2e20ee4eafb4ff2afd 100644 --- a/templates/md/property.ejs +++ b/templates/md/property.ejs @@ -18,10 +18,20 @@ * defined in <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= name %>)<% } else { %>this schema<% } %> -### Type +### <%=name %> Type +<% if (schema.type==="string") { %> +<%- include("string-type",{schema:schema,_:_}) %> +<% } else { %> +Unknown type `<%= schema.type %>`. +```json +<%- JSON.stringify(schema, null, 2) %> +``` + +<% } %> + ### Known Values diff --git a/templates/md/string-type.ejs b/templates/md/string-type.ejs new file mode 100644 index 0000000000000000000000000000000000000000..4c803c0de1fdf5e1626f6f0f47c8dd9c9492ff52 --- /dev/null +++ b/templates/md/string-type.ejs @@ -0,0 +1,7 @@ +<% /** + * 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 + */ %> +This is a string. \ No newline at end of file