From 880449bfbe84c5aa7598d5ddcaf407495b539e2d Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Thu, 14 Dec 2017 14:53:22 +0000 Subject: [PATCH] #14 basic array handling --- examples/docs/README.md | 1 + examples/docs/arrays.schema.md | 81 +++++++++++++++++++ examples/docs/constants.schema.md | 2 +- examples/docs/definitions.schema.md | 2 +- examples/docs/enums.schema.md | 2 +- examples/docs/examples.schema.md | 2 +- examples/generated-schemas/arrays.schema.json | 29 +++++++ examples/schemas/arrays.schema.json | 29 +++++++ lib/markdownWriter.js | 16 +++- 9 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 examples/docs/arrays.schema.md create mode 100644 examples/generated-schemas/arrays.schema.json create mode 100644 examples/schemas/arrays.schema.json diff --git a/examples/docs/README.md b/examples/docs/README.md index 5c3bfe0..63125fd 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 0000000..5d5186e --- /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 518253c..d3aa5ec 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 32326e0..d86a83c 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 d3d0ded..473e2e8 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 9b44b8d..57f409e 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 0000000..44df550 --- /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 0000000..489deb5 --- /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 32f3bf1..52de01a 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), -- GitLab