Skip to content
Snippets Groups Projects
Commit 625d8378 authored by Lars Trieloff's avatar Lars Trieloff
Browse files

#14 list schema hierarchy

parent 926970fe
No related branches found
No related tags found
No related merge requests found
Showing
with 252 additions and 10 deletions
......@@ -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`
......
......@@ -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
......@@ -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
---
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
......@@ -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
......@@ -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
---
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
......@@ -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
......@@ -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
......@@ -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
{
"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
{
"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
{
"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
{
"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
......@@ -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 ],
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment