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 Contact Json Schema asyncapi#539
- Loading branch information
Showing
7 changed files
with
85 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,60 @@ | ||
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/contact.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../definitions/3.0.0/schema.json')) | ||
.addSchema(require('../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(infoJsonSchema); | ||
|
||
describe('Contact', () => { | ||
it('empty', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Contact with empty body is valid'); | ||
}); | ||
|
||
it('without required properties', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Contact without required properties is valid'); | ||
}); | ||
|
||
it('only required properties', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Contact is valid with only required properties'); | ||
}); | ||
|
||
it('extended', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Contact can be extended'); | ||
}); | ||
|
||
it('wrongly extended', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Contact is not valid when was wrongly extended'); | ||
assert(validator.errors[0].message === 'must NOT have additional properties'); | ||
assert(validator.errors[0].params.additionalProperty === 'ext-number'); | ||
assert(validator.errors.length === 1); | ||
}); | ||
}); |
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 @@ | ||
{} |
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,10 @@ | ||
{ | ||
"name" : "AsyncAPI", | ||
"url" : "https://www.asyncapi.com", | ||
"email" : "[email protected]", | ||
"x-number" : 0, | ||
"x-string" : "", | ||
"x-object" : { | ||
"property" : { } | ||
} | ||
} |
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 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
test/definitions/3.0.0/contact/without required properties.json
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 @@ | ||
{} |
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 @@ | ||
{ | ||
"name" : "AsyncAPI", | ||
"url" : "https://www.asyncapi.com", | ||
"email" : "[email protected]", | ||
"x-number" : 0, | ||
"x-string" : "", | ||
"x-object" : { | ||
"property" : { } | ||
}, | ||
"ext-number": 1 | ||
} |
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