diff --git a/examples/docs/README.md b/examples/docs/README.md index be7456240bf8a77948e862d3ced4de6ad8923cb2..3af4eca2efde0fcff27e760d8f3e7e1e952a99fb 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -8,8 +8,10 @@ * [Abstract](./abstract.schema.md) – `https://example.com/schemas/abstract` * [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` * [Example](./example.schema.md) – `https://example.com/schemas/example` +* [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` diff --git a/examples/docs/abstract.schema.md b/examples/docs/abstract.schema.md index ea39f5b6ed82e961af02340215a937afafeec658..4544fbd09627391d0e6879d908e5d7cec297e182 100644 --- a/examples/docs/abstract.schema.md +++ b/examples/docs/abstract.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Abstract +# Abstract Schema + ``` https://example.com/schemas/abstract ``` @@ -14,4 +15,5 @@ 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) | + --- \ No newline at end of file diff --git a/examples/docs/custom.schema.md b/examples/docs/custom.schema.md index c81635f74243b42e13cad55c8736a35111b3c400..9a4bc1cb79aa9436a97e50877ad0fd2852063dca 100644 --- a/examples/docs/custom.schema.md +++ b/examples/docs/custom.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Custom +# Custom Schema + ``` https://example.com/schemas/custom ``` @@ -14,4 +15,5 @@ This is an extensible schema. It has `definitions`, that can be used in other sc | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Can be instantiated | Yes | Allowed | [custom.schema.json](custom.schema.json) | + --- \ No newline at end of file diff --git a/examples/docs/deepextending.schema.md b/examples/docs/deepextending.schema.md new file mode 100644 index 0000000000000000000000000000000000000000..ce410cfcc937fbb0c1b5da356c27c55fe71b87b5 --- /dev/null +++ b/examples/docs/deepextending.schema.md @@ -0,0 +1,26 @@ + +--- +template: reference +foo: bar +--- + +# Custom Schema + +``` +https://example.com/schemas/deepextending +``` + +This is an extending schema. It is extending another extending schema. It pulls `definitions` from other schemas. + +| Abstract | Extensible | Custom Properties | Defined In | +|----------|------------|-------------------|------------| +| Can be instantiated | Yes | Forbidden | [deepextending.schema.json](deepextending.schema.json) | + +## Schema Hierarchy + +* Custom `schema.$id` + * [Extensible](extensible.schema.md) `https://example.com/schemas/extensible` + * [Definitions](definitions.schema.md) `https://example.com/schemas/definitions` + * [Extending](extending.schema.md) `https://example.com/schemas/extending` + +--- \ No newline at end of file diff --git a/examples/docs/definitions.schema.md b/examples/docs/definitions.schema.md index f1c52de31428345f5994647e93115d8d34fefdf7..b96fbdab09675a054f7776ce02fedb6db8ba477d 100644 --- a/examples/docs/definitions.schema.md +++ b/examples/docs/definitions.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Definitions +# Definitions Schema + ``` https://example.com/schemas/definitions ``` @@ -15,4 +16,5 @@ It is imported using `allOf` and `$ref`. | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Can be instantiated | Yes | Forbidden | [definitions.schema.json](definitions.schema.json) | + --- \ No newline at end of file diff --git a/examples/docs/example.schema.md b/examples/docs/example.schema.md index 8c3bfa8a073fd335331bf0099dc6b5326b796334..9b5260f2183ed8103af2d1a0d85c55503e0025bf 100644 --- a/examples/docs/example.schema.md +++ b/examples/docs/example.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Example +# Example Schema + ``` https://example.com/schemas/example ``` @@ -14,4 +15,5 @@ This is an example schema with examples. Too many examples? There can never be t | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Can be instantiated | No | Forbidden | [example.schema.json](example.schema.json) | + --- \ No newline at end of file diff --git a/examples/docs/extending.schema.md b/examples/docs/extending.schema.md new file mode 100644 index 0000000000000000000000000000000000000000..b64a706817f3b51292766a91600191834a446572 --- /dev/null +++ b/examples/docs/extending.schema.md @@ -0,0 +1,25 @@ + +--- +template: reference +foo: bar +--- + +# Extending Schema + +``` +https://example.com/schemas/extending +``` + +This is an extending schema. It pulls `definitions` from other schemas. + +| Abstract | Extensible | Custom Properties | Defined In | +|----------|------------|-------------------|------------| +| Can be instantiated | Yes | Forbidden | [extending.schema.json](extending.schema.json) | + +## Schema Hierarchy + +* Extending `schema.$id` + * [Extensible](extensible.schema.md) `https://example.com/schemas/extensible` + * [Definitions](definitions.schema.md) `https://example.com/schemas/definitions` + +--- \ No newline at end of file diff --git a/examples/docs/extensible.schema.md b/examples/docs/extensible.schema.md index 735a5986db587cc747614111776e56d4010370e6..8073e9fb9af06079c7997ea7f646047ab90d1106 100644 --- a/examples/docs/extensible.schema.md +++ b/examples/docs/extensible.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Extensible +# Extensible Schema + ``` https://example.com/schemas/extensible ``` @@ -14,4 +15,5 @@ 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) | + --- \ No newline at end of file diff --git a/examples/docs/simple.schema.md b/examples/docs/simple.schema.md index 7a9d09980eafed02e44561acd422625cd803ab21..20ef824e54da4f1c65d77a8b6c5e1c761c2a5ab5 100644 --- a/examples/docs/simple.schema.md +++ b/examples/docs/simple.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Simple +# Simple Schema + ``` https://example.com/schemas/simple ``` @@ -14,4 +15,5 @@ This is a *very* simple example of a JSON schema. There is only one property. | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| | Can be instantiated | No | Forbidden | [simple.schema.json](simple.schema.json) | + --- \ No newline at end of file diff --git a/examples/docs/subdir/subdir.schema.md b/examples/docs/subdir/subdir.schema.md index b7fee1d11a98cfb331e9e3131f9f1d63c1c516f6..a8f378657c9d2e69ffd97c4a13efaf63cf1f5918 100644 --- a/examples/docs/subdir/subdir.schema.md +++ b/examples/docs/subdir/subdir.schema.md @@ -4,7 +4,8 @@ template: reference foo: bar --- -# Subdir +# Subdir Schema + ``` https://example.com/schemas/subdir/subdir ``` @@ -14,4 +15,5 @@ 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) | + --- \ No newline at end of file diff --git a/examples/generated-schemas/deepextending.schema.json b/examples/generated-schemas/deepextending.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..b5228aa1971eef78d9cfa5ffba95f743c83efda9 --- /dev/null +++ b/examples/generated-schemas/deepextending.schema.json @@ -0,0 +1,43 @@ +{ + "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/deepextending", + "title": "Custom", + "description": "This is an extending schema. It is extending another extending schema. It pulls `definitions` from other schemas.", + "type": "object", + "meta:extensible": true, + "meta:extends": [ + "https://example.com/schemas/definitions", + "https://example.com/schemas/extensible", + "https://example.com/schemas/extending" + ], + "definitions": { + "fourth": { + "properties": { + "hey": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + } + }, + "allOf": [ + { + "$ref": "https://example.com/schemas/extensible#/definitions/second" + }, + { + "$ref": "https://example.com/schemas/definitions#/definitions/myid" + }, + { + "$ref": "https://example.com/schemas/extending#/definitions/third" + }, + { + "$ref": "#/definitions/fourth" + } + ] +} \ No newline at end of file diff --git a/examples/generated-schemas/extending.schema.json b/examples/generated-schemas/extending.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..41b19a2aa12ece77c37c647cabdb89164050b632 --- /dev/null +++ b/examples/generated-schemas/extending.schema.json @@ -0,0 +1,39 @@ +{ + "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/extending", + "title": "Extending", + "description": "This is an extending schema. It pulls `definitions` from other schemas.", + "type": "object", + "meta:extensible": true, + "meta:extends": [ + "https://example.com/schemas/definitions", + "https://example.com/schemas/extensible" + ], + "definitions": { + "third": { + "properties": { + "baz": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + } + }, + "allOf": [ + { + "$ref": "https://example.com/schemas/extensible#/definitions/second" + }, + { + "$ref": "https://example.com/schemas/definitions#/definitions/myid" + }, + { + "$ref": "#/definitions/third" + } + ] +} \ No newline at end of file diff --git a/examples/schemas/deepextending.schema.json b/examples/schemas/deepextending.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..fd0f03e13b47df2300dff2e79a22bef9a9fc0d27 --- /dev/null +++ b/examples/schemas/deepextending.schema.json @@ -0,0 +1,35 @@ +{ + "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/deepextending", + "title": "Custom", + "description": "This is an extending schema. It is extending another extending schema. It pulls `definitions` from other schemas.", + "type": "object", + "meta:extensible": true, + "meta:extends": [ + "https://example.com/schemas/definitions", + "https://example.com/schemas/extensible", + "https://example.com/schemas/extending" + ], + "definitions": { + "fourth": { + "properties": { + "hey": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + } + }, + "allOf": [ + { "$ref": "https://example.com/schemas/extensible#/definitions/second"}, + { "$ref": "https://example.com/schemas/definitions#/definitions/myid" }, + { "$ref": "https://example.com/schemas/extending#/definitions/third" }, + { "$ref": "#/definitions/fourth" } + ] +} \ No newline at end of file diff --git a/examples/schemas/extending.schema.json b/examples/schemas/extending.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..b58a7687ebb945a37d2ded34b79f8681d62c7599 --- /dev/null +++ b/examples/schemas/extending.schema.json @@ -0,0 +1,33 @@ +{ + "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/extending", + "title": "Extending", + "description": "This is an extending schema. It pulls `definitions` from other schemas.", + "type": "object", + "meta:extensible": true, + "meta:extends": [ + "https://example.com/schemas/definitions", + "https://example.com/schemas/extensible" + ], + "definitions": { + "third": { + "properties": { + "baz": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + } + }, + "allOf": [ + { "$ref": "https://example.com/schemas/extensible#/definitions/second"}, + { "$ref": "https://example.com/schemas/definitions#/definitions/myid" }, + { "$ref": "#/definitions/third" } + ] +} \ No newline at end of file diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index 51d91e679ee5c61a2f5ee2f337715a246e88b562..d7ba95752759ee0a79cf04212a30fb2919d2dce8 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -41,7 +41,6 @@ function custom(schema) { } function schemaProps(schema, schemaPath, filename) { - console.log(_.keys(schema)); return { // if there are definitions, but no properties abstract: (schema.definitions !== undefined && _.keys(schema.properties).length === 0) ? 'Cannot be instantiated' : 'Can be instantiated', @@ -51,6 +50,18 @@ function schemaProps(schema, schemaPath, filename) { }; } +function flatten(dependencies) { + let deps = []; + if (dependencies) { + const key = _.keys(dependencies)[0]; + deps = _.toPairs(dependencies[key]).map(([ first, second ]) => { + second.$id = first; + return second; + }); + } + return deps; +} + const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) { var ctx = { schema: schema, @@ -60,6 +71,7 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen }; console.log(filename); + //console.log(dependencyMap); // this structure allows us to have separate templates for each element. Instead of having // one huge template, each block can be built individually @@ -67,6 +79,7 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen [ 'frontmatter.ejs', { meta: schema.metaElements } ], [ 'header.ejs', { schema: schema, + dependencies: flatten(dependencyMap), props: schemaProps(schema, schemaPath, filename) } ], //[ 'divider.ejs', null ], //[ 'topSchema.ejs', ctx ], diff --git a/templates/md/header.ejs b/templates/md/header.ejs index 13e72e2e341f19c54e06d7c86a4b7c28e59e5ad3..d2c23654bf5dd281f7cf8488f72798d2dab76b50 100644 --- a/templates/md/header.ejs +++ b/templates/md/header.ejs @@ -4,7 +4,9 @@ * 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.title %> +# <%=schema.title %> Schema + + ``` <%= schema.$id %> ``` @@ -16,4 +18,14 @@ | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| -| <%=props.abstract %> | <%=props.extensible %> | <%=props.custom %> | [<%=props.original %>](<%=props.original %>) | \ No newline at end of file +| <%=props.abstract %> | <%=props.extensible %> | <%=props.custom %> | [<%=props.original %>](<%=props.original %>) | + +<% if (dependencies.length > 0) { %> +## Schema Hierarchy + + +* <%=schema.title %> `schema.$id` +<% _.forEach(dependencies, ({$linkVal, $linkPath, $id}) => { %> + * [<%= $linkVal %>](<%=$linkPath %>) `<%= $id %>` +<% }); %> +<% } %> \ No newline at end of file