Skip to content
Snippets Groups Projects
Unverified Commit 8286cb9d authored by Lars Trieloff's avatar Lars Trieloff Committed by GitHub
Browse files

Merge pull request #81 from adobe/greenkeeper/initial

Update dependencies to enable Greenkeeper :palm_tree:
parents 96e926fc 85992550
Branches
Tags 1.1.0
No related merge requests found
# JSON Schema Markdown Tools # JSON Schema Markdown Tools
[![CircleCI](https://circleci.com/gh/adobe/jsonschema2md.svg?style=svg)](https://circleci.com/gh/adobe/jsonschema2md) [![CircleCI](https://circleci.com/gh/adobe/jsonschema2md.svg?style=svg)](https://circleci.com/gh/adobe/jsonschema2md) [![Greenkeeper badge](https://badges.greenkeeper.io/adobe/jsonschema2md.svg)](https://greenkeeper.io/)
Documenting and validating complex JSON Schemas can be hard. This tool makes it easier by providing a number of scripts that can turn JSON Schema files into readable Markdown documentation that is ready for consumption on GitHub or processed using Jekyll or other static site generators. Documenting and validating complex JSON Schemas can be hard. This tool makes it easier by providing a number of scripts that can turn JSON Schema files into readable Markdown documentation that is ready for consumption on GitHub or processed using Jekyll or other static site generators.
...@@ -31,6 +31,19 @@ $ node cli.js ...@@ -31,6 +31,19 @@ $ node cli.js
$ node cli.js -d examples/schemas -o examples/docs $ node cli.js -d examples/schemas -o examples/docs
# generated output for whole folder is written to ./examples/docs # generated output for whole folder is written to ./examples/docs
``` ```
## JSON Schema Draft Versions
`jsonschema2md` assumes `draft-07` by default. If your schemas are not on `draft-07`, you can specify the draft version using the `-v` or `--draft` flag.
```bash
# run against JSON Schema Draft 04
$ node cli.js -d examples/schemas -o examples/docs -v 04
```
```bash
# run against JSON Schema Draft 06
$ node cli.js -d examples/schemas -o examples/docs -v 06
```
### Installing the `jsonschema2md` Command Line Tools ### Installing the `jsonschema2md` Command Line Tools
......
...@@ -36,6 +36,9 @@ var argv = require('optimist') ...@@ -36,6 +36,9 @@ var argv = require('optimist')
.alias('e', 'schema-extension') .alias('e', 'schema-extension')
.describe('e', 'JSON Schema file extension eg. schema.json or json') .describe('e', 'JSON Schema file extension eg. schema.json or json')
.alias('n', 'no-readme') .alias('n', 'no-readme')
.describe('v', 'JSON Schema Draft version to use. Supported: 04, 06, 07 (default)')
.alias('v', 'draft')
.default('v', '07')
.describe('n', 'Do not generate a README.md file in the output directory') .describe('n', 'Do not generate a README.md file in the output directory')
.describe('link-*', 'Add this file as a link the explain the * attribute, e.g. --link-abstract=abstract.md') .describe('link-*', 'Add this file as a link the explain the * attribute, e.g. --link-abstract=abstract.md')
.check(function(args) { .check(function(args) {
...@@ -50,8 +53,14 @@ var argv = require('optimist') ...@@ -50,8 +53,14 @@ var argv = require('optimist')
const docs = _.fromPairs(_.toPairs(argv).filter(([ key, value ]) => { return key.startsWith('link-'); }).map(([ key, value ]) => { return [ key.substr(5), value ];})); const docs = _.fromPairs(_.toPairs(argv).filter(([ key, value ]) => { return key.startsWith('link-'); }).map(([ key, value ]) => { return [ key.substr(5), value ];}));
var ajv = new Ajv({ allErrors: true, messages:true }); var ajv = new Ajv({ allErrors: true, messages:true, schemaId: 'auto' });
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); console.log(argv.v);
if (argv.v === '06'||argv.v === 6) {
console.log('enabling draft-06 support');
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
} else if (argv.v === '04' || argv.v === 4) {
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
}
var schemaPathMap = {}; var schemaPathMap = {};
var metaElements = {}; var metaElements = {};
var schemaPath = path.resolve(argv.d); var schemaPath = path.resolve(argv.d);
......
...@@ -152,6 +152,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen ...@@ -152,6 +152,8 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
dependencyMap:dependencyMap dependencyMap:dependencyMap
}; };
outDir = outDir ? outDir : path.resolve(path.join('.', 'out'));
console.log(filename); console.log(filename);
//console.log(dependencyMap); //console.log(dependencyMap);
let propertiesSlugs = createGithubSlugs(_.keys(schema.properties)); let propertiesSlugs = createGithubSlugs(_.keys(schema.properties));
...@@ -248,7 +250,6 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen ...@@ -248,7 +250,6 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
}); });
return Promise.reduce(Promise.map(multi, render), build, '').then(str => { return Promise.reduce(Promise.map(multi, render), build, '').then(str => {
//console.log('Writing markdown (promise)');
const mdfile = path.basename(filename).slice(0, -5)+ '.md'; const mdfile = path.basename(filename).slice(0, -5)+ '.md';
return writeFile(path.join(path.join(outDir), path.dirname(filename.substr(schemaPath.length))), mdfile, str); return writeFile(path.join(path.join(outDir), path.dirname(filename.substr(schemaPath.length))), mdfile, str);
}).then(out => { }).then(out => {
......
{ {
"name": "@adobe/jsonschema2md", "name": "@adobe/jsonschema2md",
"description": "Validate and document complex JSON Schemas the easy way.", "description": "Validate and document complex JSON Schemas the easy way.",
"version": "1.0.6", "version": "1.1.0",
"main": "lib/main.js", "main": "lib/main.js",
"bin": { "bin": {
"jsonschema2md": "./cli.js" "jsonschema2md": "./cli.js"
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"cover": "istanbul cover --root lib --print detail jasmine" "cover": "istanbul cover --root lib --print detail jasmine"
}, },
"dependencies": { "dependencies": {
"ajv": "^5.0.1-beta", "ajv": "^6.5.4",
"async": "^2.0.1", "async": "^2.0.1",
"bluebird": "^3.5.1", "bluebird": "^3.5.1",
"ejs": "^2.4.2", "ejs": "^2.4.2",
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
"optimist": "^0.6.1", "optimist": "^0.6.1",
"readdirp": "^2.1.0", "readdirp": "^2.1.0",
"valid-url": "1.0.9", "valid-url": "1.0.9",
"winston": "^2.2.0" "winston": "^3.1.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^4.10.0", "eslint": "^5.6.1",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"jasmine": "~2.8.0", "jasmine": "~3.2.0",
"jasmine-diff": "^0.1.3", "jasmine-diff": "^0.1.3",
"npm-snapshot": "^1.0.3" "npm-snapshot": "^1.0.3"
}, },
......
...@@ -48,7 +48,8 @@ describe('Compare results', () => { ...@@ -48,7 +48,8 @@ describe('Compare results', () => {
'--link-abstract', '--link-abstract',
'abstract.md', 'abstract.md',
'--link-status', '--link-status',
'status.md' 'status.md',
'-v', '06'
]); ]);
ls.on('close', code => { ls.on('close', code => {
expect(code).toEqual(0); expect(code).toEqual(0);
......
...@@ -14,7 +14,7 @@ describe('writeFiles module', () => { ...@@ -14,7 +14,7 @@ describe('writeFiles module', () => {
spyOn(ejs, 'renderFile'); spyOn(ejs, 'renderFile');
}); });
it('should invoke ejs.renderFile with the topSchema ejs template', () => { it('should invoke ejs.renderFile with the topSchema ejs template', () => {
markdownWriter('somefile', { 'my':'schema' }, 'some/path'); markdownWriter('somefile.schema.json', { '$id': 'myschema', 'my':'schema' }, 'some/path');
var renderArgs = ejs.renderFile.calls.argsFor(0); var renderArgs = ejs.renderFile.calls.argsFor(0);
expect(renderArgs); expect(renderArgs);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment