diff --git a/examples/docs/abstract.schema.md b/examples/docs/abstract.schema.md index 2433c8b6c277e09873f496b44581fab4ce316af3..842df19ecd96c5608d295aeeaef3e9ee86983174 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 c942cb04c1349ec741f61735720120304b642125..5bebd8a24a65ad58228c06e5235dba130f76ea66 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 19bb89ff0fc1fcb075747c4e552319b02c669bfc..f7dde70eaf0bd7fa769597db45c12845710e8d87 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 6c8eddb0db7e16840ea8c5127f88455cb6dff4ea..e361ec7b2a2a2005aa2a3a95c0d9ca8b724b1a06 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 865b6eb73f08423cfbd1ca520c14301bd4ed2165..4f05fdadb4b63d2c76d057c6e775f9e99eca74e3 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 c98c552647aa049d65c0545c4bfa72dfe84f856f..e96a4bc602108160c6f1a84e733fd5583c528400 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 722b6e833c7e91159df2a586bcea753b5397e887..c4825d6a82f0dc366da9b6f5657df43abb919919 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 a49eeed39baa1fb130f4ebc4d26aaf0125d90c15..13e72e2e341f19c54e06d7c86a4b7c28e59e5ad3 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