diff --git a/examples/docs/README.md b/examples/docs/README.md index ecc614e906bc7cd0d894da2b70daf23a3ef5b48a..be7456240bf8a77948e862d3ced4de6ad8923cb2 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -7,6 +7,7 @@ ## / * [Abstract](./abstract.schema.md) – `https://example.com/schemas/abstract` +* [Custom](./custom.schema.md) – `https://example.com/schemas/custom` * [Definitions](./definitions.schema.md) – `https://example.com/schemas/definitions` * [Example](./example.schema.md) – `https://example.com/schemas/example` * [Extensible](./extensible.schema.md) – `https://example.com/schemas/extensible` diff --git a/examples/docs/abstract.schema.md b/examples/docs/abstract.schema.md index c035b2eba6ebcdfb04c45a9aaf271d1e55d242ed..ea39f5b6ed82e961af02340215a937afafeec658 100644 --- a/examples/docs/abstract.schema.md +++ b/examples/docs/abstract.schema.md @@ -13,5 +13,5 @@ This is an abstract schema. It has `definitions`, but does not declare any prope | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| -| Cannot be instantiated | Is extensible | true | [abstract.schema.json](abstract.schema.json) | +| 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 new file mode 100644 index 0000000000000000000000000000000000000000..c81635f74243b42e13cad55c8736a35111b3c400 --- /dev/null +++ b/examples/docs/custom.schema.md @@ -0,0 +1,17 @@ + +--- +template: reference +foo: bar +--- + +# Custom +``` +https://example.com/schemas/custom +``` + +This is an extensible schema. It has `definitions`, that can be used in other schemas. Additionally, it allows custom properties. + +| 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/definitions.schema.md b/examples/docs/definitions.schema.md index cc35ca474f57b9901dcfee109bab573d5e4a15e2..f1c52de31428345f5994647e93115d8d34fefdf7 100644 --- a/examples/docs/definitions.schema.md +++ b/examples/docs/definitions.schema.md @@ -14,5 +14,5 @@ It is imported using `allOf` and `$ref`. | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| -| Can be instantiated | Is extensible | true | [definitions.schema.json](definitions.schema.json) | +| 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 add444b6f695b9ed15ed039fad6ec5d20e89adec..8c3bfa8a073fd335331bf0099dc6b5326b796334 100644 --- a/examples/docs/example.schema.md +++ b/examples/docs/example.schema.md @@ -13,5 +13,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 | Is not extensible | true | [example.schema.json](example.schema.json) | +| Can be instantiated | No | Forbidden | [example.schema.json](example.schema.json) | --- \ No newline at end of file diff --git a/examples/docs/extensible.schema.md b/examples/docs/extensible.schema.md index 1056513d41da29450f36c2e44b65f773eb019e2c..735a5986db587cc747614111776e56d4010370e6 100644 --- a/examples/docs/extensible.schema.md +++ b/examples/docs/extensible.schema.md @@ -13,5 +13,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 | Is extensible | true | [extensible.schema.json](extensible.schema.json) | +| 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 af3cf5bfe9e62894be9470167e96b92212d2140b..7a9d09980eafed02e44561acd422625cd803ab21 100644 --- a/examples/docs/simple.schema.md +++ b/examples/docs/simple.schema.md @@ -13,5 +13,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 | Is not extensible | true | [simple.schema.json](simple.schema.json) | +| 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 73c5fcfacf0040e19713357f188517541a6aade6..b7fee1d11a98cfb331e9e3131f9f1d63c1c516f6 100644 --- a/examples/docs/subdir/subdir.schema.md +++ b/examples/docs/subdir/subdir.schema.md @@ -13,5 +13,5 @@ A schema in a sub directory | Abstract | Extensible | Custom Properties | Defined In | |----------|------------|-------------------|------------| -| Cannot be instantiated | Is extensible | true | [subdir/subdir.schema.json](subdir/subdir.schema.json) | +| 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/custom.schema.json b/examples/generated-schemas/custom.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..febfea6ee878b3c4264528df9722c6120197fadf --- /dev/null +++ b/examples/generated-schemas/custom.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/custom", + "title": "Custom", + "description": "This is an extensible schema. It has `definitions`, that can be used in other schemas. Additionally, it allows custom properties.", + "type": "object", + "meta:extensible": true, + "definitions": { + "first": { + "properties": { + "foo": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + }, + "second": { + "properties": { + "bar": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + } + }, + "allOf": [ + { + "$ref": "https://ns.adobe.com/xdm/common/extensible.schema.json#/definitions/@context" + }, + { + "$ref": "#/definitions/first" + }, + { + "$ref": "#/definitions/second" + } + ] +} \ No newline at end of file diff --git a/examples/schemas/custom.schema.json b/examples/schemas/custom.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..d80987f603f08e371a26ec8f5cd3e154f73a5513 --- /dev/null +++ b/examples/schemas/custom.schema.json @@ -0,0 +1,37 @@ +{ + "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/custom", + "title": "Custom", + "description": "This is an extensible schema. It has `definitions`, that can be used in other schemas. Additionally, it allows custom properties.", + "type": "object", + "meta:extensible": true, + "definitions": { + "first": { + "properties": { + "foo": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + }, + "second": { + "properties": { + "bar": { + "type": "string", + "description": "A unique identifier given to every addressable thing." + } + } + } + }, + "allOf": [ + { "$ref": "https://ns.adobe.com/xdm/common/extensible.schema.json#/definitions/@context"}, + { "$ref": "#/definitions/first" }, + { "$ref": "#/definitions/second" } + ] +} \ No newline at end of file diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index 79f2a78c38b9826819ae689b204393f35fce84d9..51d91e679ee5c61a2f5ee2f337715a246e88b562 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -29,13 +29,24 @@ function assoc(obj, key, value) { return obj; } +function custom(schema) { + if (schema.allOf) { + for (let i=0; i<schema.allOf.length; i++) { + if (schema.allOf[i].$ref && schema.allOf[i].$ref === 'https://ns.adobe.com/xdm/common/extensible.schema.json#/definitions/@context') { + return true; + } + } + } + return false; +} + 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', extensible: (schema.definitions !== undefined || schema['meta:extensible'] === true) ? 'Yes' : 'No', - custom: true, + custom: custom(schema) ? 'Allowed' : 'Forbidden', original: filename.substr(schemaPath.length).substr(1), }; }