feat: support $id, #384
parent
917f20c5c3
commit
4f631e61b8
44
lib/ajv.js
44
lib/ajv.js
|
@ -69,6 +69,7 @@ function Ajv(opts) {
|
||||||
this._loadingSchemas = {};
|
this._loadingSchemas = {};
|
||||||
this._compilations = [];
|
this._compilations = [];
|
||||||
this.RULES = rules();
|
this.RULES = rules();
|
||||||
|
this._getId = chooseGetId(opts);
|
||||||
|
|
||||||
opts.loopRequired = opts.loopRequired || Infinity;
|
opts.loopRequired = opts.loopRequired || Infinity;
|
||||||
if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
|
if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
|
||||||
|
@ -136,9 +137,10 @@ function addSchema(schema, key, _skipValidation, _meta) {
|
||||||
for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
|
for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (schema.id !== undefined && typeof schema.id != 'string')
|
var id = this._getId(schema);
|
||||||
|
if (id !== undefined && typeof id != 'string')
|
||||||
throw new Error('schema id must be string');
|
throw new Error('schema id must be string');
|
||||||
key = resolve.normalizeId(key || schema.id);
|
key = resolve.normalizeId(key || id);
|
||||||
checkUnique(this, key);
|
checkUnique(this, key);
|
||||||
this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
|
this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +195,7 @@ function validateSchema(schema, throwOrLogError) {
|
||||||
function defaultMeta(self) {
|
function defaultMeta(self) {
|
||||||
var meta = self._opts.meta;
|
var meta = self._opts.meta;
|
||||||
self._opts.defaultMeta = typeof meta == 'object'
|
self._opts.defaultMeta = typeof meta == 'object'
|
||||||
? meta.id || meta
|
? self._getId(meta) || meta
|
||||||
: self.getSchema(META_SCHEMA_ID)
|
: self.getSchema(META_SCHEMA_ID)
|
||||||
? META_SCHEMA_ID
|
? META_SCHEMA_ID
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -273,7 +275,7 @@ function removeSchema(schemaKeyRef) {
|
||||||
var serialize = this._opts.serialize;
|
var serialize = this._opts.serialize;
|
||||||
var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
|
var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
|
||||||
this._cache.del(cacheKey);
|
this._cache.del(cacheKey);
|
||||||
var id = schemaKeyRef.id;
|
var id = this._getId(schemaKeyRef);
|
||||||
if (id) {
|
if (id) {
|
||||||
id = resolve.normalizeId(id);
|
id = resolve.normalizeId(id);
|
||||||
delete this._schemas[id];
|
delete this._schemas[id];
|
||||||
|
@ -305,12 +307,12 @@ function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
|
||||||
|
|
||||||
shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
|
shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
|
||||||
|
|
||||||
var id = resolve.normalizeId(schema.id);
|
var id = resolve.normalizeId(this._getId(schema));
|
||||||
if (id && shouldAddSchema) checkUnique(this, id);
|
if (id && shouldAddSchema) checkUnique(this, id);
|
||||||
|
|
||||||
var willValidate = this._opts.validateSchema !== false && !skipValidation;
|
var willValidate = this._opts.validateSchema !== false && !skipValidation;
|
||||||
var recursiveMeta;
|
var recursiveMeta;
|
||||||
if (willValidate && !(recursiveMeta = schema.id && schema.id == schema.$schema))
|
if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
|
||||||
this.validateSchema(schema, true);
|
this.validateSchema(schema, true);
|
||||||
|
|
||||||
var localRefs = resolve.ids.call(this, schema);
|
var localRefs = resolve.ids.call(this, schema);
|
||||||
|
@ -374,6 +376,34 @@ function _compile(schemaObj, root) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function chooseGetId(opts) {
|
||||||
|
switch (opts.schemaId) {
|
||||||
|
case '$id': return _get$Id;
|
||||||
|
case 'id': return _getId;
|
||||||
|
default: return _get$IdOrId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _getId(schema) {
|
||||||
|
if (schema.$id) console.warn('schema $id ignored', schema.$id);
|
||||||
|
return schema.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _get$Id(schema) {
|
||||||
|
if (schema.id) console.warn('schema id ignored', schema.id);
|
||||||
|
return schema.$id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _get$IdOrId(schema) {
|
||||||
|
if (schema.$id && schema.id && schema.$id != schema.id)
|
||||||
|
throw new Error('schema $id is different from id');
|
||||||
|
return schema.$id || schema.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert array of error message objects to string
|
* Convert array of error message objects to string
|
||||||
* @this Ajv
|
* @this Ajv
|
||||||
|
@ -413,7 +443,7 @@ function addDraft6MetaSchema(self) {
|
||||||
var $dataSchema;
|
var $dataSchema;
|
||||||
if (self._opts.$data) {
|
if (self._opts.$data) {
|
||||||
$dataSchema = require('./refs/$data.json');
|
$dataSchema = require('./refs/$data.json');
|
||||||
self.addMetaSchema($dataSchema, $dataSchema.id, true);
|
self.addMetaSchema($dataSchema, $dataSchema.$id, true);
|
||||||
}
|
}
|
||||||
if (self._opts.meta === false) return;
|
if (self._opts.meta === false) return;
|
||||||
var metaSchema = require('./refs/json-schema-draft-06.json');
|
var metaSchema = require('./refs/json-schema-draft-06.json');
|
||||||
|
|
|
@ -68,7 +68,7 @@ function resolveSchema(root, ref) {
|
||||||
/* jshint validthis: true */
|
/* jshint validthis: true */
|
||||||
var p = url.parse(ref, false, true)
|
var p = url.parse(ref, false, true)
|
||||||
, refPath = _getFullPath(p)
|
, refPath = _getFullPath(p)
|
||||||
, baseId = getFullPath(root.schema.id);
|
, baseId = getFullPath(this._getId(root.schema));
|
||||||
if (refPath !== baseId) {
|
if (refPath !== baseId) {
|
||||||
var id = normalizeId(refPath);
|
var id = normalizeId(refPath);
|
||||||
var refVal = this._refs[id];
|
var refVal = this._refs[id];
|
||||||
|
@ -89,7 +89,7 @@ function resolveSchema(root, ref) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!root.schema) return;
|
if (!root.schema) return;
|
||||||
baseId = getFullPath(root.schema.id);
|
baseId = getFullPath(this._getId(root.schema));
|
||||||
}
|
}
|
||||||
return getJsonPointer.call(this, p, baseId, root.schema, root);
|
return getJsonPointer.call(this, p, baseId, root.schema, root);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,8 @@ function resolveRecursive(root, ref, parsedRef) {
|
||||||
var schema = res.schema;
|
var schema = res.schema;
|
||||||
var baseId = res.baseId;
|
var baseId = res.baseId;
|
||||||
root = res.root;
|
root = res.root;
|
||||||
if (schema.id) baseId = resolveUrl(baseId, schema.id);
|
var id = this._getId(schema);
|
||||||
|
if (id) baseId = resolveUrl(baseId, id);
|
||||||
return getJsonPointer.call(this, parsedRef, baseId, schema, root);
|
return getJsonPointer.call(this, parsedRef, baseId, schema, root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +124,9 @@ function getJsonPointer(parsedRef, baseId, schema, root) {
|
||||||
part = util.unescapeFragment(part);
|
part = util.unescapeFragment(part);
|
||||||
schema = schema[part];
|
schema = schema[part];
|
||||||
if (schema === undefined) break;
|
if (schema === undefined) break;
|
||||||
if (schema.id && !PREVENT_SCOPE_CHANGE[part]) baseId = resolveUrl(baseId, schema.id);
|
var id;
|
||||||
|
if (!PREVENT_SCOPE_CHANGE[part] && (id = this._getId(schema)))
|
||||||
|
baseId = resolveUrl(baseId, id);
|
||||||
if (schema.$ref) {
|
if (schema.$ref) {
|
||||||
var $ref = resolveUrl(baseId, schema.$ref);
|
var $ref = resolveUrl(baseId, schema.$ref);
|
||||||
var res = resolveSchema.call(this, root, $ref);
|
var res = resolveSchema.call(this, root, $ref);
|
||||||
|
@ -227,7 +230,7 @@ function resolveUrl(baseId, id) {
|
||||||
function resolveIds(schema) {
|
function resolveIds(schema) {
|
||||||
/* eslint no-shadow: 0 */
|
/* eslint no-shadow: 0 */
|
||||||
/* jshint validthis: true */
|
/* jshint validthis: true */
|
||||||
var id = normalizeId(schema.id);
|
var id = normalizeId(this._getId(schema));
|
||||||
var localRefs = {};
|
var localRefs = {};
|
||||||
_resolveIds.call(this, schema, getFullPath(id, false), id);
|
_resolveIds.call(this, schema, getFullPath(id, false), id);
|
||||||
return localRefs;
|
return localRefs;
|
||||||
|
@ -239,11 +242,9 @@ function resolveIds(schema) {
|
||||||
for (var i=0; i<schema.length; i++)
|
for (var i=0; i<schema.length; i++)
|
||||||
_resolveIds.call(this, schema[i], fullPath+'/'+i, baseId);
|
_resolveIds.call(this, schema[i], fullPath+'/'+i, baseId);
|
||||||
} else if (schema && typeof schema == 'object') {
|
} else if (schema && typeof schema == 'object') {
|
||||||
if (typeof schema.id == 'string') {
|
var id = this._getId(schema);
|
||||||
var id = baseId = baseId
|
if (typeof id == 'string') {
|
||||||
? url.resolve(baseId, schema.id)
|
id = baseId = normalizeId(baseId ? url.resolve(baseId, id) : id);
|
||||||
: schema.id;
|
|
||||||
id = normalizeId(id);
|
|
||||||
|
|
||||||
var refVal = this._refs[id];
|
var refVal = this._refs[id];
|
||||||
if (typeof refVal == 'string') refVal = this._refs[refVal];
|
if (typeof refVal == 'string') refVal = this._refs[refVal];
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
|
|
||||||
{{
|
{{
|
||||||
var $async = it.schema.$async === true
|
var $async = it.schema.$async === true
|
||||||
, $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref');
|
, $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref')
|
||||||
|
, $id = it.self._getId(it.schema);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{{? it.isTop }}
|
{{? it.isTop }}
|
||||||
|
@ -40,8 +41,8 @@
|
||||||
{{?}}
|
{{?}}
|
||||||
(data, dataPath, parentData, parentDataProperty, rootData) {
|
(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||||
'use strict';
|
'use strict';
|
||||||
{{? it.schema.id && (it.opts.sourceCode || it.opts.processCode) }}
|
{{? $id && (it.opts.sourceCode || it.opts.processCode) }}
|
||||||
{{= '/\*# sourceURL=' + it.schema.id + ' */' }}
|
{{= '/\*# sourceURL=' + $id + ' */' }}
|
||||||
{{?}}
|
{{?}}
|
||||||
{{?}}
|
{{?}}
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@
|
||||||
, $lvl = it.level = 0
|
, $lvl = it.level = 0
|
||||||
, $dataLvl = it.dataLevel = 0
|
, $dataLvl = it.dataLevel = 0
|
||||||
, $data = 'data';
|
, $data = 'data';
|
||||||
it.rootId = it.resolve.fullPath(it.root.schema.id);
|
it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
|
||||||
it.baseId = it.baseId || it.rootId;
|
it.baseId = it.baseId || it.rootId;
|
||||||
delete it.isTop;
|
delete it.isTop;
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@
|
||||||
, $dataLvl = it.dataLevel
|
, $dataLvl = it.dataLevel
|
||||||
, $data = 'data' + ($dataLvl || '');
|
, $data = 'data' + ($dataLvl || '');
|
||||||
|
|
||||||
if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id);
|
if ($id) it.baseId = it.resolve.url(it.baseId, $id);
|
||||||
|
|
||||||
if ($async && !it.async) throw new Error('async schema in sync schema');
|
if ($async && !it.async) throw new Error('async schema in sync schema');
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#",
|
|
||||||
"$schema": "http://json-schema.org/draft-06/schema#",
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#",
|
||||||
"description": "Meta-schema for $data reference (JSON-schema extension proposal)",
|
"description": "Meta-schema for $data reference (JSON-schema extension proposal)",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [ "$data" ],
|
"required": [ "$data" ],
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-06/schema#",
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
"id": "http://json-schema.org/draft-06/schema#",
|
"$id": "http://json-schema.org/draft-06/schema#",
|
||||||
"title": "Core schema meta-schema",
|
"title": "Core schema meta-schema",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"schemaArray": {
|
"schemaArray": {
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
},
|
},
|
||||||
"type": ["object", "boolean"],
|
"type": ["object", "boolean"],
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"$id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "uri-ref"
|
"format": "uri-ref"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1170,4 +1170,53 @@ describe('Ajv Options', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('schemaId', function() {
|
||||||
|
describe('= undefined (default)', function() {
|
||||||
|
it('should throw if both id and $id are available and different', function() {
|
||||||
|
var ajv = new Ajv;
|
||||||
|
|
||||||
|
ajv.compile({
|
||||||
|
id: 'mySchema',
|
||||||
|
$id: 'mySchema'
|
||||||
|
});
|
||||||
|
|
||||||
|
should.throw(function() {
|
||||||
|
ajv.compile({
|
||||||
|
id: 'mySchema1',
|
||||||
|
$id: 'mySchema2'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('= "id"', function() {
|
||||||
|
it('should use id and ignore $id', function() {
|
||||||
|
var ajv = new Ajv({schemaId: 'id'});
|
||||||
|
|
||||||
|
ajv.addSchema({ id: 'mySchema1', type: 'string' });
|
||||||
|
var validate = ajv.getSchema('mySchema1');
|
||||||
|
validate('foo') .should.equal(true);
|
||||||
|
validate(1) .should.equal(false);
|
||||||
|
|
||||||
|
validate = ajv.compile({ $id: 'mySchema2', type: 'string' });
|
||||||
|
should.not.exist(ajv.getSchema('mySchema2'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('= "$id"', function() {
|
||||||
|
it('should use $id and ignore id', function() {
|
||||||
|
var ajv = new Ajv({schemaId: '$id'});
|
||||||
|
|
||||||
|
ajv.addSchema({ $id: 'mySchema1', type: 'string' });
|
||||||
|
var validate = ajv.getSchema('mySchema1');
|
||||||
|
validate('foo') .should.equal(true);
|
||||||
|
validate(1) .should.equal(false);
|
||||||
|
|
||||||
|
validate = ajv.compile({ id: 'mySchema2', type: 'string' });
|
||||||
|
should.not.exist(ajv.getSchema('mySchema2'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"description": "root ref in remote ref (#13)",
|
"description": "root ref in remote ref (#13)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
"id": "http://localhost:1234/object",
|
{
|
||||||
|
"id": "http://localhost:1234/issue13_1",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": { "$ref": "name.json#/definitions/orNull" }
|
"name": { "$ref": "name.json#/definitions/orNull" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$id": "http://localhost:1234/issue13_2",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": { "$ref": "name.json#/definitions/orNull" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "string is valid",
|
"description": "string is valid",
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"description": "ref in remote ref with ids",
|
"description": "ref in remote ref with ids",
|
||||||
"schema": {
|
"schemas": [
|
||||||
"id": "http://localhost:1234/issue14a.json",
|
{
|
||||||
|
"id": "http://localhost:1234/issue14a_1.json",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "$ref": "foo.json" }
|
"items": { "$ref": "foo.json" }
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$id": "http://localhost:1234/issue14a_2.json",
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "foo.json" }
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "string is valid",
|
"description": "string is valid",
|
||||||
|
@ -29,11 +36,18 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "remote ref in definitions in remote ref with ids (#14)",
|
"description": "remote ref in definitions in remote ref with ids (#14)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
"id": "http://localhost:1234/issue14b.json",
|
{
|
||||||
|
"id": "http://localhost:1234/issue14b_1.json",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "$ref": "buu.json#/definitions/buu" }
|
"items": { "$ref": "buu.json#/definitions/buu" }
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$id": "http://localhost:1234/issue14b_2.json",
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "buu.json#/definitions/buu" }
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "string is valid",
|
"description": "string is valid",
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"description": "sibling property has id (#170)",
|
"description": "sibling property has id (#170)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "http://example.com/base_object",
|
"id": "http://example.com/base_object_1",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"title": {
|
"title": {
|
||||||
|
@ -16,6 +17,22 @@
|
||||||
"file-entry": { "type": "string" }
|
"file-entry": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "http://example.com/base_object_2",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"title": {
|
||||||
|
"$id": "http://example.com/title",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"file": { "$ref": "#/definitions/file-entry" }
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"file-entry": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "valid object",
|
"description": "valid object",
|
||||||
|
@ -37,9 +54,10 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "sibling item has id",
|
"description": "sibling item has id",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "http://example.com/base_array",
|
"id": "http://example.com/base_array_1",
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
|
@ -52,6 +70,22 @@
|
||||||
"file-entry": { "type": "string" }
|
"file-entry": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "http://example.com/base_array_2",
|
||||||
|
"type": "array",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"$id": "http://example.com/0",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{ "$ref": "#/definitions/file-entry" }
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"file-entry": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "valid array",
|
"description": "valid array",
|
||||||
|
@ -67,9 +101,10 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "sibling schema in anyOf has id",
|
"description": "sibling schema in anyOf has id",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "http://example.com/base_anyof",
|
"id": "http://example.com/base_anyof_1",
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
"id": "http://example.com/0",
|
"id": "http://example.com/0",
|
||||||
|
@ -81,6 +116,21 @@
|
||||||
"def": { "type": "string" }
|
"def": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "http://example.com/base_anyof_2",
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$id": "http://example.com/0",
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
{ "$ref": "#/definitions/def" }
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"def": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "valid string",
|
"description": "valid string",
|
||||||
|
@ -101,9 +151,10 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "sibling schema in oneOf has id",
|
"description": "sibling schema in oneOf has id",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "http://example.com/base_oneof",
|
"id": "http://example.com/base_oneof_1",
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{
|
{
|
||||||
"id": "http://example.com/0",
|
"id": "http://example.com/0",
|
||||||
|
@ -115,6 +166,21 @@
|
||||||
"def": { "type": "string" }
|
"def": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "http://example.com/base_oneof_2",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"$id": "http://example.com/0",
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
{ "$ref": "#/definitions/def" }
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"def": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "valid string",
|
"description": "valid string",
|
||||||
|
@ -135,9 +201,10 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "sibling schema in allOf has id",
|
"description": "sibling schema in allOf has id",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "http://example.com/base_allof",
|
"id": "http://example.com/base_allof_1",
|
||||||
"allOf": [
|
"allOf": [
|
||||||
{
|
{
|
||||||
"id": "http://example.com/0",
|
"id": "http://example.com/0",
|
||||||
|
@ -150,6 +217,22 @@
|
||||||
"def": { "type": "string" }
|
"def": { "type": "string" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "http://example.com/base_allof_2",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$id": "http://example.com/0",
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 3
|
||||||
|
},
|
||||||
|
{ "$ref": "#/definitions/def" }
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"def": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "valid string",
|
"description": "valid string",
|
||||||
|
@ -165,9 +248,10 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "sibling schema in dependencies has id",
|
"description": "sibling schema in dependencies has id",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "http://example.com/base_dependencies",
|
"id": "http://example.com/base_dependencies_1",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"foo": {
|
"foo": {
|
||||||
|
@ -180,6 +264,22 @@
|
||||||
"def": { "required": [ "baz" ] }
|
"def": { "required": [ "baz" ] }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "http://example.com/base_dependencies_2",
|
||||||
|
"type": "object",
|
||||||
|
"dependencies": {
|
||||||
|
"foo": {
|
||||||
|
"$id": "http://example.com/foo",
|
||||||
|
"required": [ "bar" ]
|
||||||
|
},
|
||||||
|
"bar": { "$ref": "#/definitions/def" }
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"def": { "required": [ "baz" ] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "valid object",
|
"description": "valid object",
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"description": "IDs in refs without root id (#1)",
|
"description": "IDs in refs without root id (#1)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"int": {
|
"int": {
|
||||||
"id": "#int",
|
"id": "#int",
|
||||||
|
@ -10,6 +11,16 @@
|
||||||
},
|
},
|
||||||
"$ref": "#int"
|
"$ref": "#int"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"definitions": {
|
||||||
|
"int": {
|
||||||
|
"$id": "#int",
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$ref": "#int"
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{ "description": "valid", "data": 1, "valid": true },
|
{ "description": "valid", "data": 1, "valid": true },
|
||||||
{ "description": "invalid", "data": "foo", "valid": false }
|
{ "description": "invalid", "data": "foo", "valid": false }
|
||||||
|
@ -17,8 +28,9 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "IDs in refs with root id",
|
"description": "IDs in refs with root id",
|
||||||
"schema": {
|
"schemas": [
|
||||||
"id": "http://example.com/int.json",
|
{
|
||||||
|
"id": "http://example.com/int_1.json",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"int": {
|
"int": {
|
||||||
"id": "#int",
|
"id": "#int",
|
||||||
|
@ -27,6 +39,17 @@
|
||||||
},
|
},
|
||||||
"$ref": "#int"
|
"$ref": "#int"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$id": "http://example.com/int_2.json",
|
||||||
|
"definitions": {
|
||||||
|
"int": {
|
||||||
|
"$id": "#int",
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$ref": "#int"
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{ "description": "valid", "data": 1, "valid": true },
|
{ "description": "valid", "data": 1, "valid": true },
|
||||||
{ "description": "invalid", "data": "foo", "valid": false }
|
{ "description": "invalid", "data": "foo", "valid": false }
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"description": "Recursive reference (#27)",
|
"description": "Recursive reference (#27)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"id": "testrec",
|
"id": "testrec_1",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"layout": {
|
"layout": {
|
||||||
|
@ -28,6 +29,34 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||||
|
"$id": "testrec_2",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"layout": {
|
||||||
|
"$id": "layout",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"layout": { "type": "string" },
|
||||||
|
"panels": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"anyOf": [
|
||||||
|
{ "type": "string" },
|
||||||
|
{ "$ref": "layout" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"layout",
|
||||||
|
"panels"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "empty object is valid",
|
"description": "empty object is valid",
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"description": "id property in referenced schema in object that is not a schema (#63)",
|
"description": "id property in referenced schema in object that is not a schema (#63)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
|
{
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"title": { "$ref": "http://json-schema.org/draft-04/schema#/properties/title" }
|
"title": { "$ref": "http://json-schema.org/draft-04/schema#/properties/title" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type" : "object",
|
||||||
|
"properties": {
|
||||||
|
"title": { "$ref": "http://json-schema.org/draft-06/schema#/properties/title" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{
|
{
|
||||||
"description": "empty object is valid",
|
"description": "empty object is valid",
|
||||||
|
|
|
@ -12,10 +12,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "hash ref inside hash ref in remote ref with id (#70, was passing)",
|
"description": "hash ref inside hash ref in remote ref with id (#70, was passing)",
|
||||||
"schema": {
|
"schemas": [
|
||||||
"id": "http://example.com/my_schema.json",
|
{
|
||||||
|
"id": "http://example.com/my_schema_1.json",
|
||||||
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
|
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"$id": "http://example.com/my_schema_2.json",
|
||||||
|
"$ref": "http://json-schema.org/draft-06/schema#/definitions/positiveIntegerDefault0"
|
||||||
|
}
|
||||||
|
],
|
||||||
"tests": [
|
"tests": [
|
||||||
{ "data": 1, "valid": true, "description": "positive integer is valid" },
|
{ "data": 1, "valid": true, "description": "positive integer is valid" },
|
||||||
{ "data": 0, "valid": true, "description": "zero is valid" },
|
{ "data": 0, "valid": true, "description": "zero is valid" },
|
||||||
|
|
Loading…
Reference in New Issue