From d3eea7e2633f6a3f3e02bf91cfc3a509ea99d261 Mon Sep 17 00:00:00 2001
From: Lars Trieloff <trieloff@adobe.com>
Date: Wed, 13 Dec 2017 19:04:05 +0000
Subject: [PATCH] #14 highlight abstract schemas

---
 examples/docs/abstract.schema.md      |  5 +++++
 examples/docs/definitions.schema.md   |  5 +++++
 examples/docs/example.schema.md       |  5 +++++
 examples/docs/simple.schema.md        |  5 +++++
 examples/docs/subdir/subdir.schema.md |  5 +++++
 lib/markdownWriter.js                 | 18 +++++++++++++++---
 spec/lib/writeFiles.spec.js           |  2 +-
 templates/md/header.ejs               |  9 ++++++++-
 8 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/examples/docs/abstract.schema.md b/examples/docs/abstract.schema.md
index 2433c8b..842df19 100644
--- a/examples/docs/abstract.schema.md
+++ b/examples/docs/abstract.schema.md
@@ -8,5 +8,10 @@ foo: bar
 ```
 https://example.com/schemas/abstract
 ```
+
 This is an abstract schema. It has `definitions`, but does not declare any properties
+
+| Abstract | Extensible | Custom Properties | Defined In |
+|----------|------------|-------------------|------------|
+| true | true | true | [abstract.schema.json](abstract.schema.json) |
 ---
\ No newline at end of file
diff --git a/examples/docs/definitions.schema.md b/examples/docs/definitions.schema.md
index c942cb0..5bebd8a 100644
--- a/examples/docs/definitions.schema.md
+++ b/examples/docs/definitions.schema.md
@@ -8,6 +8,11 @@ foo: bar
 ```
 https://example.com/schemas/definitions
 ```
+
 This is an example of using a `definitions` object within a schema.
 It is imported using `allOf` and `$ref`.
+
+| Abstract | Extensible | Custom Properties | Defined In |
+|----------|------------|-------------------|------------|
+| false | true | true | [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 19bb89f..f7dde70 100644
--- a/examples/docs/example.schema.md
+++ b/examples/docs/example.schema.md
@@ -8,5 +8,10 @@ foo: bar
 ```
 https://example.com/schemas/example
 ```
+
 This is an example schema with examples. Too many examples? There can never be too many examples!
+
+| Abstract | Extensible | Custom Properties | Defined In |
+|----------|------------|-------------------|------------|
+|  | true | true | [example.schema.json](example.schema.json) |
 ---
\ No newline at end of file
diff --git a/examples/docs/simple.schema.md b/examples/docs/simple.schema.md
index 6c8eddb..e361ec7 100644
--- a/examples/docs/simple.schema.md
+++ b/examples/docs/simple.schema.md
@@ -8,5 +8,10 @@ foo: bar
 ```
 https://example.com/schemas/simple
 ```
+
 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) |
 ---
\ No newline at end of file
diff --git a/examples/docs/subdir/subdir.schema.md b/examples/docs/subdir/subdir.schema.md
index 865b6eb..4f05fda 100644
--- a/examples/docs/subdir/subdir.schema.md
+++ b/examples/docs/subdir/subdir.schema.md
@@ -8,5 +8,10 @@ foo: bar
 ```
 https://example.com/schemas/subdir/subdir
 ```
+
 A schema in a sub directory
+
+| Abstract | Extensible | Custom Properties | Defined In |
+|----------|------------|-------------------|------------|
+| true | true | true | [subdir/subdir.schema.json](subdir/subdir.schema.json) |
 ---
\ No newline at end of file
diff --git a/lib/markdownWriter.js b/lib/markdownWriter.js
index c98c552..e96a4bc 100644
--- a/lib/markdownWriter.js
+++ b/lib/markdownWriter.js
@@ -14,7 +14,6 @@ const pejs = Promise.promisifyAll(ejs);
 var validUrl = require('valid-url');
 
 function render([ template, context ]) {
-  console.log('rendering ' + template);
   return pejs.renderFileAsync(template, context, { debug: false });
 }
 
@@ -30,6 +29,17 @@ function assoc(obj, key, value) {
   return obj;
 }
 
+function schemaProps(schema, schemaPath, filename) {
+  console.log(_.keys(schema.properties));
+  return {
+    // if there are definitions, but no properties
+    abstract: schema.definitions && _.keys(schema.properties).length === 0,
+    extensible: true,
+    custom: true,
+    original: filename.substr(schemaPath.length).substr(1),
+  };
+}
+
 const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) {
   var ctx = {
     schema: schema,
@@ -38,13 +48,15 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
     dependencyMap:dependencyMap
   };
 
-  console.log(schema);
+  console.log(filename);
 
   // this structure allows us to have separate templates for each element. Instead of having
   // one huge template, each block can be built individually
   const multi = [
     [ 'frontmatter.ejs', { meta: schema.metaElements } ],
-    [ 'header.ejs', { schema: schema } ],
+    [ 'header.ejs', {
+      schema: schema,
+      props: schemaProps(schema, schemaPath, filename) } ],
     //[ 'divider.ejs', null ],
     //[ 'topSchema.ejs', ctx ],
     [ 'divider.ejs', null ]
diff --git a/spec/lib/writeFiles.spec.js b/spec/lib/writeFiles.spec.js
index 722b6e8..c4825d6 100644
--- a/spec/lib/writeFiles.spec.js
+++ b/spec/lib/writeFiles.spec.js
@@ -14,7 +14,7 @@ describe('writeFiles module', () => {
       spyOn(ejs, 'renderFile');
     });
     it('should invoke ejs.renderFile with the topSchema ejs template', () => {
-      markdownWriter('somefile', { 'my':'schema' });
+      markdownWriter('somefile', { 'my':'schema' }, 'some/path');
       var renderArgs = ejs.renderFile.calls.argsFor(0);
       expect(renderArgs);
     });
diff --git a/templates/md/header.ejs b/templates/md/header.ejs
index a49eeed..13e72e2 100644
--- a/templates/md/header.ejs
+++ b/templates/md/header.ejs
@@ -9,4 +9,11 @@
 <%= schema.$id %>
 ```
 
-<%= schema.description %>
\ No newline at end of file
+
+<%= schema.description %>
+
+
+
+| Abstract | Extensible | Custom Properties | Defined In |
+|----------|------------|-------------------|------------|
+| <%=props.abstract %> | <%=props.extensible %> | <%=props.custom %> | [<%=props.original %>](<%=props.original %>) |
\ No newline at end of file
-- 
GitLab