diff --git a/examples/docs/README.md b/examples/docs/README.md index 264fafca73d6a2dca5de2ee870baaba6df4e67d6..ea96b3fceaafb335085bc9722b87ff2002d1c17b 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -7,6 +7,7 @@ ## / * [Abstract](./abstract.schema.md) – `https://example.com/schemas/abstract` +* [Constant Types](./constants.schema.md) – `https://example.com/schemas/constants` * [Custom](./custom.schema.md) – `https://example.com/schemas/custom` * [Custom](./deepextending.schema.md) – `https://example.com/schemas/deepextending` * [Definitions](./definitions.schema.md) – `https://example.com/schemas/definitions` diff --git a/examples/docs/constants.schema.md b/examples/docs/constants.schema.md new file mode 100644 index 0000000000000000000000000000000000000000..32320f08c276a2ab557092c1c16c5f64d17912d5 --- /dev/null +++ b/examples/docs/constants.schema.md @@ -0,0 +1,46 @@ +--- +template: reference +foo: bar +--- + +# Constant Types Schema + +``` +https://example.com/schemas/constants +``` + +This is an example schema with examples for properties with constant values + +| Abstract | Extensible | Custom Properties | Defined In | +|----------|------------|-------------------|------------| +| Can be instantiated | No | Forbidden | [constants.schema.json](constants.schema.json) | + +# Constant Types Properties + +| Property | Type | Required | Defined by | +|----------|------|----------|------------| +| [hello](#hello) | `const` | **Required** | Constant Types (this schema) | + +## hello + +A simple string, without strong constraints. + +`hello` +* is **required** +* type: `const` +* defined in this schema + +The value of this property **must** be equal to: + +```json +"World" +``` + +### Known Values + +| Value | Description | +|-------|-------------| +| `hi` | Welcome | +| `bye` | Farewell | + + diff --git a/examples/docs/simpletypes.schema.md b/examples/docs/simpletypes.schema.md index a528e8ba553ff5da64a5f076b2c9eabc96bc6600..b6354dee722f7c0e0b3b53deea0245ad4790fb65 100644 --- a/examples/docs/simpletypes.schema.md +++ b/examples/docs/simpletypes.schema.md @@ -31,10 +31,10 @@ This is an example schema with examples for multiple types and their constraints | [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) | -| [interger_unconstrained](#interger_unconstrained) | complex | Optional | Simple Types (this schema) | -| [interger_constrained](#interger_constrained) | complex | Optional | Simple Types (this schema) | +| [interger_unconstrained](#interger_unconstrained) | `integer` | Optional | Simple Types (this schema) | +| [interger_constrained](#interger_constrained) | `integer` | Optional | Simple Types (this schema) | | [number_constrained](#number_constrained) | `number` | Optional | Simple Types (this schema) | -| [integer_threes](#integer_threes) | complex | Optional | Simple Types (this schema) | +| [integer_threes](#integer_threes) | `integer` | Optional | Simple Types (this schema) | | [yesno](#yesno) | `boolean` | Optional | Simple Types (this schema) | ## string_unconstrained @@ -400,7 +400,7 @@ Just a whole number. I don't like fractions. `interger_unconstrained` * is optional -* type: complex +* type: `integer` * defined in this schema ### interger_unconstrained Type @@ -425,7 +425,7 @@ Just a whole number. I don't like fractions. Don't get too small `interger_constrained` * is optional -* type: complex +* type: `integer` * defined in this schema ### interger_constrained Type @@ -475,7 +475,7 @@ Guess what number is valid `integer_threes` * is optional -* type: complex +* type: `integer` * defined in this schema ### integer_threes Type diff --git a/examples/generated-schemas/constants.schema.json b/examples/generated-schemas/constants.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..6ac15c7d3c10e8cf49e123af50ad2c36d7614f32 --- /dev/null +++ b/examples/generated-schemas/constants.schema.json @@ -0,0 +1,23 @@ +{ + "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/constants", + "title": "Constant Types", + "type": "object", + "description": "This is an example schema with examples for properties with constant values", + "properties": { + "hello": { + "type": "string", + "const": "World", + "description": "A simple string, without strong constraints." + } + }, + "required": [ + "hello" + ] +} \ No newline at end of file diff --git a/examples/schemas/constants.schema.json b/examples/schemas/constants.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..f3843c3635b2dd4eea7866506e9626710c372603 --- /dev/null +++ b/examples/schemas/constants.schema.json @@ -0,0 +1,23 @@ +{ + "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/constants", + "title": "Constant Types", + "type": "object", + "description": "This is an example schema with examples for properties with constant values", + "properties": { + "hello": { + "type": "string", + "const": "World", + "description": "A simple string, without strong constraints." + } + }, + "required": [ + "hello" + ] +} diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index 8342788e70dbd3626085d4587b5096bb6dd22064..2ad3140084cdf866176ccb6bccfc10bed5373521 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -78,12 +78,16 @@ function stringifyExamples(examples) { function simpletype(prop) { const type = prop.type; - if (type==='string') { + if (prop.const!==undefined) { + prop.simpletype = '`const`'; + } else if (type==='string') { prop.simpletype = '`string`'; } else if (type==='number') { prop.simpletype = '`number`'; } else if (type==='boolean') { prop.simpletype = '`boolean`'; + } else if (type==='integer') { + prop.simpletype = '`integer`'; } else if (type==='object') { prop.simpletype = '`object`'; } else if (type==='array') { diff --git a/templates/md/boolean-type.ejs b/templates/md/boolean-type.ejs new file mode 100644 index 0000000000000000000000000000000000000000..a5789ce859ed406358659a9fd8e6dd1e7a276808 --- /dev/null +++ b/templates/md/boolean-type.ejs @@ -0,0 +1,8 @@ +<% /** + * 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.type %>` diff --git a/templates/md/property.ejs b/templates/md/property.ejs index b738fbc480c1686c6807c588c9924f73d2ce898c..328913031d7ad27aeb292d7cd3460730efa1a905 100644 --- a/templates/md/property.ejs +++ b/templates/md/property.ejs @@ -17,6 +17,15 @@ * type: <%=schema.simpletype %> * defined in <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= name %>)<% } else { %>this schema<% } %> +<% if (schema.const!==undefined) { %> +The value of this property **must** be equal to: + + +```json +<%- JSON.stringify(schema.const, null, 2) %> +``` + +<% } else { %> ### <%=name %> Type @@ -34,7 +43,7 @@ Unknown type `<%= schema.type %>`. <%- JSON.stringify(schema, null, 2) %> ``` -<% } %> +<% }} %> ### Known Values