diff --git a/examples/docs/README.md b/examples/docs/README.md index 5c3bfe0c1786b8702a522b2c70c3678a18183671..63125fdc544e8ca1518525127990da89c60c93ab 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -7,6 +7,7 @@ ## / * [Abstract](./abstract.schema.md) – `https://example.com/schemas/abstract` +* [Arrays](./arrays.schema.md) – `https://example.com/schemas/arrays` * [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` diff --git a/examples/docs/arrays.schema.md b/examples/docs/arrays.schema.md new file mode 100644 index 0000000000000000000000000000000000000000..5d5186e67b9956ea8474ee71402bae161d361278 --- /dev/null +++ b/examples/docs/arrays.schema.md @@ -0,0 +1,81 @@ +--- +template: reference +foo: bar +--- + +# Arrays Schema + +``` +https://example.com/schemas/arrays +``` + +This is an example schema with examples for multiple array types and their constraints. + +| Abstract | Extensible | Custom Properties | Defined In | +|----------|------------|-------------------|------------| +| Can be instantiated | No | Forbidden | [arrays.schema.json](arrays.schema.json) | + +# Arrays Properties + +| Property | Type | Required | Defined by | +|----------|------|----------|------------| +| [list](#list) | `string[]` | Optional | Arrays (this schema) | +| [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) | + +## list + +This is an array + +`list` +* is optional +* type: `string[]` +* defined in this schema + +### list Type + +Unknown type `array`. + +```json +{ + "type": "array", + "description": "This is an array", + "items": { + "type": "string", + "simpletype": "`string`" + }, + "simpletype": "`string[]`" +} +``` + + + + + +## intlist + +This is an array + +`intlist` +* is optional +* type: `integer[]` +* defined in this schema + +### intlist Type + +Unknown type `array`. + +```json +{ + "type": "array", + "description": "This is an array", + "items": { + "type": "integer", + "simpletype": "`integer`" + }, + "simpletype": "`integer[]`" +} +``` + + + + diff --git a/examples/docs/constants.schema.md b/examples/docs/constants.schema.md index 518253c7162fa71fb9c4c6f508bceb88966b7af3..d3aa5ec0c542688367c0e9e0ec2e9f4fbdfa5f70 100644 --- a/examples/docs/constants.schema.md +++ b/examples/docs/constants.schema.md @@ -19,7 +19,7 @@ This is an example schema with examples for properties with constant values | Property | Type | Required | Defined by | |----------|------|----------|------------| -| [hello](#hello) | `const` | **Required** | Constant Types (this schema) | +| [hello](#hello) | `const` | Optional | Constant Types (this schema) | ## hello diff --git a/examples/docs/definitions.schema.md b/examples/docs/definitions.schema.md index 32326e0d86b978c8093f706a2f463f5ad27f713c..d86a83c87d088782e4a5ce22edcc1c2f4bfbfe07 100644 --- a/examples/docs/definitions.schema.md +++ b/examples/docs/definitions.schema.md @@ -20,7 +20,7 @@ It is imported using `allOf` and `$ref`. | Property | Type | Required | Defined by | |----------|------|----------|------------| -| [id](#id) | `string` | **Required** | Definitions (this schema) | +| [id](#id) | `string` | Optional | Definitions (this schema) | ## id diff --git a/examples/docs/enums.schema.md b/examples/docs/enums.schema.md index d3d0ded4239c726f1d608b272159e6853420bb19..473e2e836b933435b273d3a1b4b6fbc2ced00744 100644 --- a/examples/docs/enums.schema.md +++ b/examples/docs/enums.schema.md @@ -19,7 +19,7 @@ This is an example schema with examples for properties with enum values | Property | Type | Required | Defined by | |----------|------|----------|------------| -| [hello](#hello) | `enum` | **Required** | Enumerated (this schema) | +| [hello](#hello) | `enum` | Optional | Enumerated (this schema) | ## hello diff --git a/examples/docs/examples.schema.md b/examples/docs/examples.schema.md index 9b44b8d1e38a39816141efec0aeeaffd4500dd55..57f409e244323ff47a5aa7ab6068cb422a537ad5 100644 --- a/examples/docs/examples.schema.md +++ b/examples/docs/examples.schema.md @@ -37,7 +37,7 @@ This is an example schema with *multiple* examples. Too many examples? There can | Property | Type | Required | Defined by | |----------|------|----------|------------| | [foo](#foo) | `string` | Optional | Examples (this schema) | -| [bar](#bar) | `string` | **Required** | Examples (this schema) | +| [bar](#bar) | `string` | Optional | Examples (this schema) | ## foo diff --git a/examples/generated-schemas/arrays.schema.json b/examples/generated-schemas/arrays.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..44df550b2fe2f950ad5cd576fc2bee1fa57fce96 --- /dev/null +++ b/examples/generated-schemas/arrays.schema.json @@ -0,0 +1,29 @@ +{ + "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/arrays", + "title": "Arrays", + "type": "object", + "description": "This is an example schema with examples for multiple array types and their constraints.", + "properties": { + "list": { + "type": "array", + "description": "This is an array", + "items": { + "type": "string" + } + }, + "intlist": { + "type": "array", + "description": "This is an array", + "items": { + "type": "integer" + } + } + } +} \ No newline at end of file diff --git a/examples/schemas/arrays.schema.json b/examples/schemas/arrays.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..489deb54750db3504c0e089317bc152608f0d170 --- /dev/null +++ b/examples/schemas/arrays.schema.json @@ -0,0 +1,29 @@ +{ + "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/arrays", + "title": "Arrays", + "type": "object", + "description": "This is an example schema with examples for multiple array types and their constraints.", + "properties": { + "list": { + "type":"array", + "description": "This is an array", + "items": { + "type": "string" + } + }, + "intlist": { + "type":"array", + "description": "This is an array", + "items": { + "type": "integer" + } + } + } +} diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index 32f3bf16c647d003ff6ae69d6c7c593031b9952a..52de01a564169d7f6aeb20c775c24f2e1ccf906a 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -67,7 +67,7 @@ function stringifyExamples(examples) { if (typeof examples === 'string') { examples = [ examples ]; } - console.log(examples); + //console.log(examples); return examples.map(example => { return JSON.stringify(example, null, 2); }); @@ -102,7 +102,17 @@ function simpletype(prop) { } else if (type==='object') { prop.simpletype = '`object`'; } else if (type==='array') { - prop.simpletype = '`array`'; + if (prop.items!==undefined) { + const innertype = simpletype(prop.items); + if (innertype.simpletype==='complex') { + prop.simpletype = '`array`'; + } else { + prop.simpletype = innertype.simpletype.replace(/`$/, '[]`'); + } + console.log(); + } else { + prop.simpletype = '`array`'; + } } else { prop.simpletype = 'complex'; } @@ -155,8 +165,6 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen } } - console.log(requiredProperties(schema.properties, schema.required)); - multi = multi.map(([ template, context ]) => { return [ path.join(__dirname, '../templates/md/' + template),