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

Merge branch 'draft-07-support' into greenkeeper/initial

parents 80637040 37c2ea09
No related branches found
No related tags found
No related merge requests found
...@@ -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);
......
...@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment