From 6cdd3cad3e995cbb081be5623838d6ef8b4aa585 Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Wed, 13 Dec 2017 19:11:40 +0000 Subject: [PATCH] #14 #7 highlight extensible schemas --- examples/docs/README.md | 1 + examples/docs/example.schema.md | 2 +- examples/docs/extensible.schema.md | 17 ++++++++++ examples/docs/simple.schema.md | 2 +- .../generated-schemas/extensible.schema.json | 32 +++++++++++++++++++ examples/schemas/extensible.schema.json | 32 +++++++++++++++++++ lib/markdownWriter.js | 6 ++-- 7 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 examples/docs/extensible.schema.md create mode 100644 examples/generated-schemas/extensible.schema.json create mode 100644 examples/schemas/extensible.schema.json diff --git a/examples/docs/README.md b/examples/docs/README.md index 13ab963..ecc614e 100644 --- a/examples/docs/README.md +++ b/examples/docs/README.md @@ -9,6 +9,7 @@ * [Abstract](./abstract.schema.md) – `https://example.com/schemas/abstract` * [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` * [Simple](./simple.schema.md) – `https://example.com/schemas/simple` ## /subdir/ diff --git a/examples/docs/example.schema.md b/examples/docs/example.schema.md index f7dde70..a9d0955 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 | |----------|------------|-------------------|------------| -| | true | true | [example.schema.json](example.schema.json) | +| false | false | true | [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 new file mode 100644 index 0000000..35d1e74 --- /dev/null +++ b/examples/docs/extensible.schema.md @@ -0,0 +1,17 @@ + +--- +template: reference +foo: bar +--- + +# Extensible +``` +https://example.com/schemas/extensible +``` + +This is an extensible schema. It has `definitions`, that can be used in other schemas + +| Abstract | Extensible | Custom Properties | Defined In | +|----------|------------|-------------------|------------| +| true | true | true | [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 e361ec7..71311cf 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 | |----------|------------|-------------------|------------| -| | true | true | [simple.schema.json](simple.schema.json) | +| false | false | true | [simple.schema.json](simple.schema.json) | --- \ No newline at end of file diff --git a/examples/generated-schemas/extensible.schema.json b/examples/generated-schemas/extensible.schema.json new file mode 100644 index 0000000..7982be0 --- /dev/null +++ b/examples/generated-schemas/extensible.schema.json @@ -0,0 +1,32 @@ +{ + "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/extensible", + "title": "Extensible", + "description": "This is an extensible schema. It has `definitions`, that can be used in other schemas", + "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." + } + } + } + } +} \ No newline at end of file diff --git a/examples/schemas/extensible.schema.json b/examples/schemas/extensible.schema.json new file mode 100644 index 0000000..7982be0 --- /dev/null +++ b/examples/schemas/extensible.schema.json @@ -0,0 +1,32 @@ +{ + "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/extensible", + "title": "Extensible", + "description": "This is an extensible schema. It has `definitions`, that can be used in other schemas", + "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." + } + } + } + } +} \ No newline at end of file diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js index e96a4bc..9d70def 100644 --- a/lib/markdownWriter.js +++ b/lib/markdownWriter.js @@ -30,11 +30,11 @@ function assoc(obj, key, value) { } function schemaProps(schema, schemaPath, filename) { - console.log(_.keys(schema.properties)); + console.log(_.keys(schema)); return { // if there are definitions, but no properties - abstract: schema.definitions && _.keys(schema.properties).length === 0, - extensible: true, + abstract: schema.definitions !== undefined && _.keys(schema.properties).length === 0, + extensible: schema.definitions !== undefined || schema['meta:extensible'] === true, custom: true, original: filename.substr(schemaPath.length).substr(1), }; -- GitLab