Skip to content

feat: test draft-7 with Ajv #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
'use strict';

var Ajv = require('ajv');
var jsonSchemaTest = require('json-schema-test');
var assert = require('assert');
const Ajv = require('ajv');
const jsonSchemaTest = require('json-schema-test');
const assert = require('assert');

var refs = {
const refs = {
'http://localhost:1234/integer.json': require('./remotes/integer.json'),
'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'),
'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json'),
'http://localhost:1234/name.json': require('./remotes/name.json')
};

runTest(4);
runTest(6);
const SKIP = {
4: ['optional/zeroTerminatedFloats'],
7: ['optional/content', 'optional/format']
};

function runTest(draft) {
var opts = {
[4, 6, 7].forEach((draft) => {
let opts = {
format: 'full',
formats: {'json-pointer': /^(?:\/(?:[^~\/]|~0|~1)*)*$/}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this is removed because you now recognize the json-pointer format automatically?

Copy link
Member Author

@epoberezkin epoberezkin Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously json-pointer format in ajv allowed hash-fragment encoding, so it had to be replaced. Now it is changed, so no need to replace it.

unknownFormats: ['iri', 'iri-reference', 'idn-hostname', 'idn-email']
};
if (draft == 4) opts.meta = false;
var ajv = new Ajv(opts);
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
if (draft == 4) ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#';
for (var uri in refs) ajv.addSchema(refs[uri], uri);

let ajv;
if (draft == 7) {
ajv = new Ajv(opts);
} else {
opts.meta = false;
ajv = new Ajv(opts);
ajv.addMetaSchema(require(`ajv/lib/refs/json-schema-draft-0${draft}.json`));
ajv._opts.defaultMeta = `http://json-schema.org/draft-0${draft}/schema#`;
}
for (const uri in refs) ajv.addSchema(refs[uri], uri);

jsonSchemaTest(ajv, {
description: 'Test suite draft-0' + draft,
suites: {tests: './tests/draft' + draft + '/{**/,}*.json'},
skip: draft == 4 ? ['optional/zeroTerminatedFloats'] : [],
description: `Test suite draft-0${draft}`,
suites: {tests: `./tests/draft${draft}/{**/,}*.json`},
skip: SKIP[draft],
cwd: __dirname,
hideFolder: 'tests/'
});
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"homepage": "https://github.com/json-schema-org/JSON-Schema-Test-Suite#readme",
"devDependencies": {
"ajv": "^5.0.4-beta.1",
"ajv": "^6.0.0-rc.0",
"json-schema-test": "^1.3.0",
"mocha": "^3.2.0"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/draft7/definitions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"description": "valid definition",
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
"tests": [
{
"description": "valid definition schema",
Expand All @@ -16,7 +16,7 @@
},
{
"description": "invalid definition",
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
"tests": [
{
"description": "invalid definition schema",
Expand Down
2 changes: 1 addition & 1 deletion tests/draft7/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
},
{
"description": "remote ref, containing refs itself",
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
"tests": [
{
"description": "remote ref valid",
Expand Down