forked from asyncapi/spec-json-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check ReferenceObject Json Schema asyncapi#539
- Loading branch information
Showing
10 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$ref": [ | ||
1, | ||
null, | ||
false, | ||
"#/components/schemas/user", | ||
{ | ||
"$ref": "#/components/schemas/user" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$ref": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$ref": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$ref": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$ref": 1234 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$ref": { | ||
"$ref": "#/components/schemas/user" | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
test/definitions/3.0.0/reference object/reference-object.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const Ajv = require('ajv'); | ||
const assert = require('assert'); | ||
const addFormats = require('ajv-formats'); | ||
const fs = require('fs'); | ||
|
||
const ajv = new Ajv({ | ||
jsonPointers: true, | ||
allErrors: true, | ||
schemaId: '$id', | ||
logger: false, | ||
validateFormats: true, | ||
strict: false, | ||
}); | ||
addFormats(ajv); | ||
|
||
const infoJsonSchema = require('../../../../definitions/3.0.0/Reference.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../definitions/3.0.0/schema.json')) | ||
.addMetaSchema(require('../../../../definitions/3.0.0/ReferenceObject.json')) | ||
.compile(infoJsonSchema); | ||
|
||
describe('ReferenceObject', () => { | ||
it('empty', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Reference with empty $ref is valid'); | ||
}); | ||
|
||
it('number', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/number.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference as number is not valid'); | ||
assert(validator.errors[0].message === 'must be string'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('object', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/object.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference as object is not valid'); | ||
assert(validator.errors[0].message === 'must be string'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('string', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/string.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference as non URI is not valid'); | ||
assert(validator.errors[0].message === 'must match format "uri-reference"'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('boolean', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/boolean.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference as boolean is not valid'); | ||
assert(validator.errors[0].message === 'must be string'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('null', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/null.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference as null is not valid'); | ||
assert(validator.errors[0].message === 'must be string'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('array', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/array.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference as array is not valid'); | ||
assert(validator.errors[0].message === 'must be string'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('URI', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/uri.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Reference in URI format is valid'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$ref": "string value" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$ref": "#/components/schemas/user" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters