-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 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
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,13 @@ | ||
{ | ||
"name": "user", | ||
"description": "User-related messages", | ||
"externalDocs": { | ||
"description" : "Find more info here", | ||
"url" : "https://example.com" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/definitions/3.0.0/models/tag/only 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,3 @@ | ||
{ | ||
"name": "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,66 @@ | ||
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/tag.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/Reference.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/ReferenceObject.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/externalDocs.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(infoJsonSchema); | ||
|
||
describe('Reference', () => { | ||
it('empty', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference with empty body is not valid'); | ||
assert(validator.errors[0].message === 'must have required property \'name\''); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('without required properties', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === false, 'Reference without required properties is not valid'); | ||
assert(validator.errors[0].message === 'must have required property \'name\''); | ||
assert(validator.errors.length === 1); | ||
}); | ||
|
||
it('only required properties', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
assert(validationResult === true, 'Reference is valid with only required properties'); | ||
}); | ||
|
||
it.skip('extended. Reason: schema doesn\'t check for extensions', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
// TODO: Is it ok? | ||
assert(validationResult === true, 'Reference extensions will not be checked'); | ||
}); | ||
|
||
it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => { | ||
const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); | ||
const validationResult = validator(info); | ||
|
||
// TODO: Is it ok? | ||
assert(validationResult === true, 'Reference extensions will not be checked'); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/definitions/3.0.0/models/tag/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,7 @@ | ||
{ | ||
"description": "User-related messages", | ||
"externalDocs": { | ||
"description" : "Find more info here", | ||
"url" : "https://example.com" | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"name": "user", | ||
"description": "User-related messages", | ||
"externalDocs": { | ||
"description" : "Find more info here", | ||
"url" : "https://example.com" | ||
}, | ||
"x-number": 0, | ||
"x-string": "", | ||
"x-object": { | ||
"property": {} | ||
}, | ||
"ext-number": 1 | ||
} |