diff --git a/examples/docs/abstract.schema.md b/examples/docs/abstract.schema.md index 8dca190952f0142470c11d010ad92d07c3d4f633..43aff6dc7d83a37f53fc342063e5b0b1beecab1c 100644 --- a/examples/docs/abstract.schema.md +++ b/examples/docs/abstract.schema.md @@ -14,3 +14,10 @@ This is an abstract schema. It has `definitions`, but does not declare any prope | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Cannot be instantiated | Yes | Forbidden | [abstract.schema.json](abstract.schema.json) | + +# Abstract Definitions + +| Property | Type | +|----------|------| +| [foo](#foo) | `string` | +| [bar](#bar) | `string` | diff --git a/examples/docs/constants.schema.md b/examples/docs/constants.schema.md index d3aa5ec0c542688367c0e9e0ec2e9f4fbdfa5f70..518253c7162fa71fb9c4c6f508bceb88966b7af3 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` | Optional | Constant Types (this schema) | +| [hello](#hello) | `const` | **Required** | Constant Types (this schema) | ## hello diff --git a/examples/docs/definitions.schema.md b/examples/docs/definitions.schema.md index d86a83c87d088782e4a5ce22edcc1c2f4bfbfe07..32326e0d86b978c8093f706a2f463f5ad27f713c 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` | Optional | Definitions (this schema) | +| [id](#id) | `string` | **Required** | Definitions (this schema) | ## id diff --git a/examples/docs/enums.schema.md b/examples/docs/enums.schema.md index 473e2e836b933435b273d3a1b4b6fbc2ced00744..d3d0ded4239c726f1d608b272159e6853420bb19 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` | Optional | Enumerated (this schema) | +| [hello](#hello) | `enum` | **Required** | Enumerated (this schema) | ## hello diff --git a/examples/docs/examples.schema.md b/examples/docs/examples.schema.md index 57f409e244323ff47a5aa7ab6068cb422a537ad5..9b44b8d1e38a39816141efec0aeeaffd4500dd55 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` | Optional | Examples (this schema) | +| [bar](#bar) | `string` | **Required** | Examples (this schema) | ## foo diff --git a/examples/docs/extensible.schema.md b/examples/docs/extensible.schema.md index 4902fcb959d0123072a01bb56f730f914fbbc9dd..d685f950b2db50115c666916c16fc142af716919 100644 --- a/examples/docs/extensible.schema.md +++ b/examples/docs/extensible.schema.md @@ -14,3 +14,10 @@ This is an extensible schema. It has `definitions`, that can be used in other sc | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Cannot be instantiated | Yes | Forbidden | [extensible.schema.json](extensible.schema.json) | + +# Extensible Definitions + +| Property | Type | +|----------|------| +| [foo](#foo) | `string` | +| [bar](#bar) | `string` | diff --git a/examples/docs/simpletypes.schema.md b/examples/docs/simpletypes.schema.md index 2e07e3fcf7dba8a9d5c9f2b0311846e1cf8d0272..f395b04d53001bc9ab3b938b97b9d1c29ee05405 100644 --- a/examples/docs/simpletypes.schema.md +++ b/examples/docs/simpletypes.schema.md @@ -35,7 +35,7 @@ This is an example schema with examples for multiple types and their constraints | [interger_constrained](#interger_constrained) | `integer` | Optional | Simple Types (this schema) | | [number_constrained](#number_constrained) | `number` | Optional | Simple Types (this schema) | | [integer_threes](#integer_threes) | `integer` | Optional | Simple Types (this schema) | -| [yesno](#yesno) | `boolean` | Optional | Simple Types (this schema) | +| [yesno](#yesno) | `boolean` | **Required** | Simple Types (this schema) | ## string_unconstrained @@ -430,7 +430,7 @@ Guess what number is valid `yesno` -* is optional +* is **required** * type: `boolean` * defined in this schema diff --git a/examples/docs/subdir/subdir.schema.md b/examples/docs/subdir/subdir.schema.md index 164a20a3035869ab28c59678efe117bca489e32c..c7dc9e8c1f78997aa09a93bab8f3f4a0f68c388f 100644 --- a/examples/docs/subdir/subdir.schema.md +++ b/examples/docs/subdir/subdir.schema.md @@ -14,3 +14,9 @@ A schema in a sub directory | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Cannot be instantiated | Yes | Forbidden | [subdir/subdir.schema.json](subdir/subdir.schema.json) | + +# Subdir Definitions + +| Property | Type | +|----------|------| +| [id](#id) | `string` | diff --git a/examples/generated-schemas/simpletypes.schema.json b/examples/generated-schemas/simpletypes.schema.json index e178175dbc578f6e9a3cff60c6755aaa9b2ae260..533c4bad2054f9ebd60b9983145ec4e4023fc7f3 100644 --- a/examples/generated-schemas/simpletypes.schema.json +++ b/examples/generated-schemas/simpletypes.schema.json @@ -123,6 +123,6 @@ } }, "required": [ - "bar" + "yesno" ] } \ No newline at end of file diff --git a/examples/schemas/simpletypes.schema.json b/examples/schemas/simpletypes.schema.json index 6facbc42e41a11fa6d77cc01b124e09d92516a4c..93f83493b99ef671bce9bc816a9e506bb128db2f 100644 --- a/examples/schemas/simpletypes.schema.json +++ b/examples/schemas/simpletypes.schema.json @@ -112,6 +112,6 @@ } }, "required": [ - "bar" + "yesno" ] } diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index a396e59abc2618da989e71fa4e9ac917cc13bbe2..31e217b1514aadd1d2c82f58137f7e2d52226afb 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -155,7 +155,7 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen ]; if (_.keys(schema.properties).length > 0) { - multi.push([ 'properties.ejs', { props: requiredProperties(schema.properties), title: schema.title } ]); + multi.push([ 'properties.ejs', { props: requiredProperties(schema.properties, schema.required), title: schema.title } ]); for (let i=0; i<_.keys(schema.properties).length;i++) { multi.push( [ 'property.ejs', { name: _.keys(schema.properties)[i], @@ -166,7 +166,24 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen } if (_.keys(schema.definitions).length > 0) { - console.log('I got definitions!'); + const abstract = {}; + for (let i=0; i<_.keys(schema.definitions).length;i++) { + if (schema.definitions[_.keys(schema.definitions)[i]].properties!==undefined) { + const definition = schema.definitions[_.keys(schema.definitions)[i]].properties; + for (let j=0; j<_.keys(definition).length;j++) { + const name = _.keys(definition)[j]; + const property = definition[_.keys(definition)[j]]; + //console.log('Checking ' + name + ' against ' + _.keys(schema.properties)); + if (_.keys(schema.properties).indexOf(name)===-1) { + abstract[name] = property; + } + } + } + } + if (_.keys(abstract).length>0) { + console.log('I got definitions!', abstract); + multi.push([ 'definitions.ejs', { props: requiredProperties(abstract), title: schema.title } ]); + } } multi = multi.map(([ template, context ]) => { diff --git a/templates/md/definitions.ejs b/templates/md/definitions.ejs new file mode 100644 index 0000000000000000000000000000000000000000..4b0295531fc6793246eb64ddb77006fce23a08e2 --- /dev/null +++ b/templates/md/definitions.ejs @@ -0,0 +1,15 @@ +<% /** + * 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 + */ %> +# <%=title %> Definitions + + + +| Property | Type | +|----------|------| +<% _.forIn(props, (schema, property, object) => { %> +| [<%= property %>](#<%= property %>) | <%= schema.simpletype %> | +<% }); %> \ No newline at end of file