From bedb502f6adc814f91c417bbcb3c662a6f51a27b Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Tue, 9 Oct 2018 11:22:31 +0000 Subject: [PATCH] introduced -v flag to switch between drafts. Fixes #80 --- cli.js | 13 +++++++++++-- spec/lib/integrationTest.spec.js | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cli.js b/cli.js index a193fe0..2046fa0 100755 --- a/cli.js +++ b/cli.js @@ -36,6 +36,9 @@ var argv = require('optimist') .alias('e', 'schema-extension') .describe('e', 'JSON Schema file extension eg. schema.json or json') .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('link-*', 'Add this file as a link the explain the * attribute, e.g. --link-abstract=abstract.md') .check(function(args) { @@ -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 ];})); -var ajv = new Ajv({ allErrors: true, messages:true }); -ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); +var ajv = new Ajv({ allErrors: true, messages:true, schemaId: 'auto' }); +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 metaElements = {}; var schemaPath = path.resolve(argv.d); diff --git a/spec/lib/integrationTest.spec.js b/spec/lib/integrationTest.spec.js index 929ff0d..ae86bfb 100644 --- a/spec/lib/integrationTest.spec.js +++ b/spec/lib/integrationTest.spec.js @@ -48,7 +48,8 @@ describe('Compare results', () => { '--link-abstract', 'abstract.md', '--link-status', - 'status.md' + 'status.md', + '-v', '06' ]); ls.on('close', code => { expect(code).toEqual(0); -- GitLab