Skip to content

Commit

Permalink
test(definitions): add example test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed May 23, 2024
1 parent c9f9810 commit d7d2106
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 20 deletions.
12 changes: 10 additions & 2 deletions test/definitions/3.0.0/models/info/contact/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const infoJsonSchema = require('../../../../../../definitions/3.0.0/contact.json');
const jsonSchemaName = 'Contact';
const jsonSchema = 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);
.compile(jsonSchema);

describe('Contact', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);
Expand Down
5 changes: 5 additions & 0 deletions test/definitions/3.0.0/models/info/contact/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "AsyncApi",
"url": "https://www.asyncapi.com",
"email": "[email protected]"
}
4 changes: 2 additions & 2 deletions test/definitions/3.0.0/models/info/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Info Object', () => {
require('./info.js');
describe('Info Test Suite', () => {
require('./info/info.js');
require('./info extensions/info-extension.js');
require('./contact/contact.js');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"x-x": "PBodiachevskii",
"x-linkedin": "https://www.linkedin.com/company/asyncapi/"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ const ajv = new Ajv({
});
addFormats(ajv);

const infoJsonSchema = require('../../../../../../definitions/3.0.0/infoExtensions.json');
const jsonSchemaName = 'Info Extensions';
const jsonSchema = require('../../../../../../definitions/3.0.0/infoExtensions.json');
const validator = ajv
.addMetaSchema(require('../../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../../extensions/linkedin/0.1.0/schema.json'))
.addSchema(require('../../../../../../extensions/x/0.1.0/schema.json'))
.compile(infoJsonSchema);
.compile(jsonSchema);

describe('InfoExtensions', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);
Expand Down
29 changes: 29 additions & 0 deletions test/definitions/3.0.0/models/info/info/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"title": "AsyncApi sample",
"version": "2.0",
"description": "short description",
"termsOfService": "https://www.asyncapi.com/about/",
"contact": {
"name": "AsyncApi",
"url": "https://www.asyncapi.com",
"email": "[email protected]"
},
"license": {
"name": "Apache License 2.0",
"url": "http://www.apache.org/licenses/"
},
"tags": [
{
"name": "user",
"description": "User-related messages",
"externalDocs": {
"description" : "Find more info here",
"url" : "https://example.com"
}
}
],
"externalDocs": {
"description": "Find more info here",
"url": "https://example.com"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@ const ajv = new Ajv({
});
addFormats(ajv);

const infoJsonSchema = require('../../../../../definitions/3.0.0/info.json');
const jsonSchemaName = 'Info';
const jsonSchema = require('../../../../../../definitions/3.0.0/info.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/infoExtensions.json'))
.addSchema(require('../../../../../definitions/3.0.0/contact.json'))
.addSchema(require('../../../../../definitions/3.0.0/license.json'))
.addSchema(require('../../../../../examples/3.0.0/ReferenceObject.json'))
.addSchema(require('../../../../../definitions/3.0.0/ReferenceObject.json'))
.addSchema(require('../../../../../definitions/3.0.0/Reference.json'))
.addSchema(require('../../../../../definitions/3.0.0/tag.json'))
.addSchema(require('../../../../../definitions/3.0.0/externalDocs.json'))
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json'))
.addSchema(require('../../../../../extensions/linkedin/0.1.0/schema.json'))
.addSchema(require('../../../../../extensions/x/0.1.0/schema.json'))
.compile(infoJsonSchema);
.addMetaSchema(require('../../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../../definitions/3.0.0/infoExtensions.json'))
.addSchema(require('../../../../../../definitions/3.0.0/contact.json'))
.addSchema(require('../../../../../../definitions/3.0.0/license.json'))
.addSchema(require('../../../../../../examples/3.0.0/ReferenceObject.json'))
.addSchema(require('../../../../../../definitions/3.0.0/ReferenceObject.json'))
.addSchema(require('../../../../../../definitions/3.0.0/Reference.json'))
.addSchema(require('../../../../../../definitions/3.0.0/tag.json'))
.addSchema(require('../../../../../../definitions/3.0.0/externalDocs.json'))
.addSchema(require('../../../../../../definitions/3.0.0/specificationExtension.json'))
.addSchema(require('../../../../../../extensions/linkedin/0.1.0/schema.json'))
.addSchema(require('../../../../../../extensions/x/0.1.0/schema.json'))
.compile(jsonSchema);

describe('Info', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/3.0.0/models/info/license/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Apache License 2.0",
"url": "http://www.apache.org/licenses/"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/models/info/license/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'License';
const infoJsonSchema = require('../../../../../../definitions/3.0.0/license.json');
const validator = ajv
.addMetaSchema(require('../../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../../definitions/3.0.0/specificationExtension.json'))
.compile(infoJsonSchema);

describe('License', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);
Expand Down
3 changes: 3 additions & 0 deletions test/definitions/3.0.0/models/reference/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$ref": "#/components/schemas/user"
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/models/reference/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'Reference';
const infoJsonSchema = require('../../../../../definitions/3.0.0/Reference.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
.addSchema(require('../../../../../definitions/3.0.0/ReferenceObject.json'))
.compile(infoJsonSchema);

describe('Reference', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);
Expand Down
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/models/tag/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "user",
"description": "User-related messages",
"externalDocs": {
"description" : "Find more info here",
"url" : "https://example.com"
}
}
8 changes: 8 additions & 0 deletions test/definitions/3.0.0/models/tag/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ajv = new Ajv({
});
addFormats(ajv);

const jsonSchemaName = 'Tag';
const infoJsonSchema = require('../../../../../definitions/3.0.0/tag.json');
const validator = ajv
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json'))
Expand All @@ -23,6 +24,13 @@ const validator = ajv
.compile(infoJsonSchema);

describe('Reference', () => {
it('example', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8'));
const validationResult = validator(info);

assert(validationResult === true, `${jsonSchemaName} example MUST be valid`);
});

it('empty', () => {
const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8'));
const validationResult = validator(info);
Expand Down

0 comments on commit d7d2106

Please sign in to comment.