diff --git a/lib/customValidators.js b/lib/customValidators.js index f55d78360..5cd24dde1 100644 --- a/lib/customValidators.js +++ b/lib/customValidators.js @@ -1,5 +1,5 @@ const ParserError = require('./errors/parser-error'); -const { parseUrlVariables, getMissingProps, groupValidationErrors, tilde } = require('./utils'); +const { parseUrlVariables, getMissingProps, groupValidationErrors, tilde, parseUrlQueryParameters, setNotProvidedParams } = require('./utils'); const validationError = 'validation-errors'; /** @@ -25,9 +25,9 @@ function validateServerVariables(parsedJSON, asyncapiYAMLorJSON, initialFormat) const missingServerVariables = getMissingProps(variables, val.variables); if (!missingServerVariables.length) return; - notProvidedVariables.set(tilde(key), - notProvidedServerVars - ? notProvidedServerVars.concat(missingServerVariables) + notProvidedVariables.set(tilde(key), + notProvidedServerVars + ? notProvidedServerVars.concat(missingServerVariables) : missingServerVariables); }); @@ -43,49 +43,6 @@ function validateServerVariables(parsedJSON, asyncapiYAMLorJSON, initialFormat) return true; } -/** - * Validates if parameters specified in the channel have corresponding parameters object defined - * - * @private - * @param {Object} parsedJSON parsed AsyncAPI document - * @param {String} asyncapiYAMLorJSON AsyncAPI document in string - * @param {String} initialFormat information of the document was oryginally JSON or YAML - * @returns {Boolean} true in case the document is valid, otherwise throws ParserError - */ -function validateChannelParams(parsedJSON, asyncapiYAMLorJSON, initialFormat) { - const chnls = parsedJSON.channels; - if (!chnls) return true; - - const chnlsMap = new Map(Object.entries(chnls)); - const notProvidedParams = new Map(); - - chnlsMap.forEach((val, key) => { - const variables = parseUrlVariables(key); - const notProvidedChannelParams = notProvidedParams.get(tilde(key)); - if (!variables) return; - - const missingChannelParams = getMissingProps(variables, val.parameters); - - if (!missingChannelParams.length) return; - - notProvidedParams.set(tilde(key), - notProvidedChannelParams - ? notProvidedChannelParams.concat(missingChannelParams) - : missingChannelParams); - }); - - if (notProvidedParams.size) { - throw new ParserError({ - type: validationError, - title: 'Not all channel parameters are described with parameter object', - parsedJSON, - validationErrors: groupValidationErrors('channels', 'channel does not have a corresponding parameter object for', notProvidedParams, asyncapiYAMLorJSON, initialFormat) - }); - } - - return true; -} - /** * Validates if operationIds are duplicated in the document * @@ -103,20 +60,20 @@ function validateOperationId(parsedJSON, asyncapiYAMLorJSON, initialFormat, oper const duplicatedOperations = new Map(); //is is a 2-dimentional array that holds information with operationId value and its path const allOperations = []; - + const addDuplicateToMap = (op, channelName, opName) => { const operationId = op.operationId; if (!operationId) return; - - const operationPath = `${ tilde(channelName) }/${ opName }/operationId`; - const isOperationIdDuplicated = allOperations.filter(v => v[0] === operationId); + + const operationPath = `${tilde(channelName)}/${opName}/operationId`; + const isOperationIdDuplicated = allOperations.filter(v => v[0] === operationId); if (!isOperationIdDuplicated.length) return allOperations.push([operationId, operationPath]); - + //isOperationIdDuplicated always holds one record and it is an array of paths, the one that is a duplicate and the one that is duplicated - duplicatedOperations.set(operationPath, isOperationIdDuplicated[0][1]); + duplicatedOperations.set(operationPath, isOperationIdDuplicated[0][1]); }; - chnlsMap.forEach((chnlObj,chnlName) => { + chnlsMap.forEach((chnlObj, chnlName) => { operations.forEach(opName => { const op = chnlObj[String(opName)]; if (op) addDuplicateToMap(op, chnlName, opName); @@ -148,7 +105,7 @@ function validateOperationId(parsedJSON, asyncapiYAMLorJSON, initialFormat, oper function validateServerSecurity(parsedJSON, asyncapiYAMLorJSON, initialFormat, specialSecTypes) { const srvs = parsedJSON.servers; if (!srvs) return true; - + const root = 'servers'; const srvsMap = new Map(Object.entries(srvs)); @@ -206,10 +163,10 @@ function validateServerSecurity(parsedJSON, asyncapiYAMLorJSON, initialFormat, s * @returns {String[]} there are 2 elements in array, index 0 is the name of the security schema object and index 1 is it's type */ function findSecuritySchema(securityName, components) { - const secSchemes = components && components.securitySchemes; - const secSchemesMap = secSchemes ? new Map(Object.entries(secSchemes)) : new Map(); + const secSchemes = components && components.securitySchemes; + const secSchemesMap = secSchemes ? new Map(Object.entries(secSchemes)) : new Map(); const schemaInfo = []; - + //using for loop here as there is no point to iterate over all entries as it is enough to find first matching element for (const [schemaName, schema] of secSchemesMap.entries()) { if (schemaName === securityName) { @@ -239,9 +196,61 @@ function isSrvrSecProperArray(schemaType, specialSecTypes, secObj, secName) { return true; } +/** + * Validates if parameters specified in the channel have corresponding parameters object defined and if name does not contain url parameters + * + * @private + * @param {Object} parsedJSON parsed AsyncAPI document + * @param {String} asyncapiYAMLorJSON AsyncAPI document in string + * @param {String} initialFormat information of the document was oryginally JSON or YAML + * @returns {Boolean} true in case the document is valid, otherwise throws ParserError + */ +function validateChannels(parsedJSON, asyncapiYAMLorJSON, initialFormat) { + const chnls = parsedJSON.channels; + if (!chnls) return true; + + const chnlsMap = new Map(Object.entries(chnls)); + const notProvidedParams = new Map(); //return object for missing parameters + const invalidChannelName = new Map(); //return object for invalid channel names with query parameters + + chnlsMap.forEach((val, key) => { + const variables = parseUrlVariables(key); + const notProvidedChannelParams = notProvidedParams.get(tilde(key)); + const queryParameters = parseUrlQueryParameters(key); + + //channel variable validation: fill return obeject with missing parameters + if (variables) { + setNotProvidedParams(variables, val, key, notProvidedChannelParams, notProvidedParams); + } + + //channel name validation: fill return object with channels containing query parameters + if (queryParameters) { + invalidChannelName.set(tilde(key), + queryParameters); + } + }); + + //combine validation errors of both checks and output them as one array + const parameterValidationErrors = groupValidationErrors('channels', 'channel does not have a corresponding parameter object for', notProvidedParams, asyncapiYAMLorJSON, initialFormat); + const nameValidationErrors = groupValidationErrors('channels', 'channel contains invalid name with url query parameters', invalidChannelName, asyncapiYAMLorJSON, initialFormat); + const allValidationErrors = parameterValidationErrors.concat(nameValidationErrors); + + //channel variable validation: throw exception if channel validation failes + if (notProvidedParams.size || invalidChannelName.size) { + throw new ParserError({ + type: validationError, + title: 'Channel validation failed', + parsedJSON, + validationErrors: allValidationErrors + }); + } + + return true; +} + module.exports = { - validateChannelParams, validateServerVariables, validateOperationId, - validateServerSecurity + validateServerSecurity, + validateChannels }; diff --git a/lib/parser.js b/lib/parser.js index 61f37ec62..1a2861918 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -5,7 +5,7 @@ const asyncapi = require('@asyncapi/specs'); const $RefParser = require('@apidevtools/json-schema-ref-parser'); const mergePatch = require('tiny-merge-patch').apply; const ParserError = require('./errors/parser-error'); -const { validateChannelParams, validateServerVariables, validateOperationId, validateServerSecurity } = require('./customValidators.js'); +const { validateChannels, validateServerVariables, validateOperationId, validateServerSecurity } = require('./customValidators.js'); const { toJS, findRefs, getLocationOf, improveAjvErrors } = require('./utils'); const AsyncAPIDocument = require('./models/asyncapi'); @@ -170,7 +170,7 @@ async function customDocumentOperations(parsedJSON, asyncapiYAMLorJSON, initialF if (!parsedJSON.channels) return; - validateChannelParams(parsedJSON, asyncapiYAMLorJSON, initialFormat); + validateChannels(parsedJSON, asyncapiYAMLorJSON, initialFormat); validateOperationId(parsedJSON, asyncapiYAMLorJSON, initialFormat, OPERATIONS); await customChannelsOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options); diff --git a/lib/utils.js b/lib/utils.js index e513bf93d..6da472f53 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -261,6 +261,19 @@ utils.parseUrlVariables = str => { return str.match(/{(.+?)}/g); }; +/** + * It parses the string and returns url parameters as string + * @function parseUrlQueryParameters + * @private + */ +utils.parseUrlQueryParameters = str => { + if (typeof str !== 'string') return; + const channelName = str; + const url = new URL(`http://${channelName}`); + + return url.search; +}; + /** * Returns an array of not existing properties in provided object with names specified in provided array * @function getMissingProps @@ -304,3 +317,25 @@ utils.groupValidationErrors = (root, errorMessage, errorElements, asyncapiYAMLor return errors; }; + +/** + * extend map with channel params missing corresponding param object + * + * @function setNotProvidedParams + * @private + * @param {Array} variables array of all identified URL variables in a channel name + * @param {Object} val the channel object for which to identify the missing parameters + * @param {String} key the channel name. + * @param {Array} notProvidedChannelParams concatinated list of missing parameters for all channels + * @param {Map} notProvidedParams result map of all missing parameters extended by this function + */ +utils.setNotProvidedParams = (variables, val, key, notProvidedChannelParams, notProvidedParams) => { + const missingChannelParams = utils.getMissingProps(variables, val.parameters); + + if (missingChannelParams.length) { + notProvidedParams.set(utils.tilde(key), + notProvidedChannelParams + ? notProvidedChannelParams.concat(missingChannelParams) + : missingChannelParams); + } +}; \ No newline at end of file diff --git a/test/customValidators_test.js b/test/customValidators_test.js index bdb6a2b85..42ea238a9 100644 --- a/test/customValidators_test.js +++ b/test/customValidators_test.js @@ -1,12 +1,12 @@ -const { validateChannelParams, validateServerVariables, validateOperationId, validateServerSecurity } = require('../lib/customValidators.js'); +const { validateServerVariables, validateOperationId, validateServerSecurity, validateChannels } = require('../lib/customValidators.js'); const chai = require('chai'); -const { offset } = require('./testsUtils'); +const { offset } = require('./testsUtils'); const expect = chai.expect; const input = 'json'; -describe('validateServerVariables()', function() { - it('should successfully validate the server variables', async function() { +describe('validateServerVariables()', function () { + it('should successfully validate the server variables', async function () { const inputString = `{ "servers": { "dummy": { @@ -21,18 +21,18 @@ describe('validateServerVariables()', function() { } }`; const parsedInput = JSON.parse(inputString); - + expect(validateServerVariables(parsedInput, inputString, input)).to.equal(true); }); - it('should successfully validate if server object not provided', async function() { + it('should successfully validate if server object not provided', async function () { const inputString = '{}'; const parsedInput = JSON.parse(inputString); - + expect(validateServerVariables(parsedInput, inputString, input)).to.equal(true); }); - it('should throw error that one of variables is not provided', async function() { + it('should throw error that one of variables is not provided', async function () { const inputString = `{ "servers": { "dummy": { @@ -70,7 +70,7 @@ describe('validateServerVariables()', function() { } }); - it('should throw error that variables are not provided if there is no variables object', async function() { + it('should throw error that variables are not provided if there is no variables object', async function () { const inputString = `{ "servers": { "dummy": { @@ -79,9 +79,9 @@ describe('validateServerVariables()', function() { } }`; const parsedInput = JSON.parse(inputString); - + try { - validateServerVariables(parsedInput, inputString, input); + validateServerVariables(parsedInput, inputString, input); } catch (e) { expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); expect(e.title).to.equal('Not all server variables are described with variable object'); @@ -103,7 +103,7 @@ describe('validateServerVariables()', function() { } }); - it('should throw error that variables are not provided even if they are but not matching the name', async function() { + it('should throw error that variables are not provided even if they are but not matching the name', async function () { const inputString = `{ "servers": { "dummy": { @@ -140,29 +140,29 @@ describe('validateServerVariables()', function() { ]); } }); -}); -it('should throw error', async function() { - const inputString = `{ - "servers": { - "dummy": { - "url": "http://{host}{port}" + it('should throw error', async function () { + const inputString = `{ + "servers": { + "dummy": { + "url": "http://{host}{port}" + } } - } - }`; - const parsedInput = JSON.parse(inputString); - - expect(() => validateServerVariables(parsedInput, inputString, input)).to.throw('Not all server variables are described with variable object'); -}); + }`; + const parsedInput = JSON.parse(inputString); -describe('validateChannelParams()', function() { - it('should successfully validate if channel object not provided', async function() { + expect(() => validateServerVariables(parsedInput, inputString, input)).to.throw('Not all server variables are described with variable object'); + }); +}); + +describe('validateChannel()', function () { + it('should successfully validate if channel object not provided', async function () { const inputDoc = {}; - - expect(validateChannelParams(inputDoc, input)).to.equal(true); + + expect(validateChannels(inputDoc, input)).to.equal(true); }); - it('should successfully validate channel param', async function() { + it('should successfully validate channel param', async function () { const inputString = `{ "channels": { "test/{test}": { @@ -178,10 +178,38 @@ describe('validateChannelParams()', function() { }`; const parsedInput = JSON.parse(inputString); - expect(validateChannelParams(parsedInput, inputString, input)).to.equal(true); + expect(validateChannels(parsedInput, inputString, input)).to.equal(true); + }); + + it('should successfully validate channel param for 2 channels', async function () { + const inputString = `{ + "channels": { + "test/{test01}": { + "parameters": { + "test01": { + "schema": { + "type": "string" + } + } + } + }, + "test/{test02}": { + "parameters": { + "test02": { + "schema": { + "type": "string" + } + } + } + } + } + }`; + const parsedInput = JSON.parse(inputString); + + expect(validateChannels(parsedInput, inputString, input)).to.equal(true); }); - it('should throw error that one of provided channel params is not declared', async function() { + it('should throw error that one of provided channel params is not declared', async function () { const inputString = `{ "channels": { "test/{test}/{testid}": { @@ -198,10 +226,10 @@ describe('validateChannelParams()', function() { const parsedInput = JSON.parse(inputString); try { - validateChannelParams(parsedInput, inputString, input); + validateChannels(parsedInput, inputString, input); } catch (e) { expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); - expect(e.title).to.equal('Not all channel parameters are described with parameter object'); + expect(e.title).to.equal('Channel validation failed'); expect(e.parsedJSON).to.deep.equal(parsedInput); expect(e.validationErrors).to.deep.equal([ { @@ -220,7 +248,7 @@ describe('validateChannelParams()', function() { } }); - it('should throw error that one of provided channel params is not declared even if other not provided params have a corresponding parameter object', async function() { + it('should throw error that one of provided channel params is not declared even if other not provided params have a corresponding parameter object', async function () { const inputString = `{ "channels": { "test/{test}": { @@ -237,10 +265,10 @@ describe('validateChannelParams()', function() { const parsedInput = JSON.parse(inputString); try { - validateChannelParams(parsedInput, inputString, input); + validateChannels(parsedInput, inputString, input); } catch (e) { expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); - expect(e.title).to.equal('Not all channel parameters are described with parameter object'); + expect(e.title).to.equal('Channel validation failed'); expect(e.parsedJSON).to.deep.equal(parsedInput); expect(e.validationErrors).to.deep.equal([ { @@ -259,7 +287,7 @@ describe('validateChannelParams()', function() { } }); - it('should throw error when there are no parameter objects', async function() { + it('should throw error when there are no parameter objects', async function () { const inputString = `{ "channels": { "test/{test}/{testid}": { @@ -269,10 +297,10 @@ describe('validateChannelParams()', function() { const parsedInput = JSON.parse(inputString); try { - validateChannelParams(parsedInput, inputString, input); + validateChannels(parsedInput, inputString, input); } catch (e) { expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); - expect(e.title).to.equal('Not all channel parameters are described with parameter object'); + expect(e.title).to.equal('Channel validation failed'); expect(e.parsedJSON).to.deep.equal(parsedInput); expect(e.validationErrors).to.deep.equal([ { @@ -291,7 +319,7 @@ describe('validateChannelParams()', function() { } }); - it('should throw error', async function() { + it('should throw error', async function () { const inputString = `{ "channels": { "test/{test}/{testid}": { @@ -300,14 +328,227 @@ describe('validateChannelParams()', function() { }`; const parsedInput = JSON.parse(inputString); - expect(() => validateChannelParams(parsedInput, inputString, input)).to.throw('Not all channel parameters are described with parameter object'); + expect(() => validateChannels(parsedInput, inputString, input)).to.throw('Channel validation failed'); }); -}); -describe('validateOperationId()', function() { + it('should successfully validate channel name without variable', async function () { + const inputString = `{ + "channels": { + "test/test01": { + } + } + }`; + const parsedInput = JSON.parse(inputString); + + expect(validateChannels(parsedInput, inputString, input)).to.equal(true); + }); + + it('should throw error that the provided channel name is invalid', async function () { + const inputString = `{ + "channels": { + "/user/signedup?foo=1": { + } + } + }`; + const parsedInput = JSON.parse(inputString); + + try { + validateChannels(parsedInput, inputString, input); + } catch (e) { + expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); + expect(e.title).to.equal('Channel validation failed'); + expect(e.parsedJSON).to.deep.equal(parsedInput); + expect(e.validationErrors).to.deep.equal([ + { + title: '/user/signedup?foo=1 channel contains invalid name with url query parameters: ?foo=1', + location: { + endColumn: 11, + endLine: 4, + endOffset: 65, + jsonPointer: '/channels/~1user~1signedup?foo=1', + startColumn: 34, + startLine: 3, + startOffset: 54 + } + } + ]); + } + }); + + it('should throw error that one of the provided channel name is invalid', async function () { + const inputString = `{ + "channels": { + "/user/signedup?foo=1": { + }, + "/user/login": { + } + } + }`; + const parsedInput = JSON.parse(inputString); + + try { + validateChannels(parsedInput, inputString, input); + } catch (e) { + expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); + expect(e.title).to.equal('Channel validation failed'); + expect(e.parsedJSON).to.deep.equal(parsedInput); + expect(e.validationErrors).to.deep.equal([ + { + title: '/user/signedup?foo=1 channel contains invalid name with url query parameters: ?foo=1', + location: { + endColumn: 9, + endLine: 4, + endOffset: 59, + jsonPointer: '/channels/~1user~1signedup?foo=1', + startColumn: 32, + startLine: 3, + startOffset: 50 + } + } + ]); + } + }); + + it('should throw error that both provided channel name is invalid', async function () { + const inputString = `{ + "channels": { + "/user/signedup?foo=1": { + }, + "/user/login?bar=2": { + } + } + }`; + const parsedInput = JSON.parse(inputString); + + try { + validateChannels(parsedInput, inputString, input); + } catch (e) { + expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); + expect(e.title).to.equal('Channel validation failed'); + expect(e.parsedJSON).to.deep.equal(parsedInput); + expect(e.validationErrors).to.deep.equal([ + { + title: '/user/signedup?foo=1 channel contains invalid name with url query parameters: ?foo=1', + location: { + endColumn: 9, + endLine: 4, + endOffset: 59, + jsonPointer: '/channels/~1user~1signedup?foo=1', + startColumn: 32, + startLine: 3, + startOffset: 50 + } + }, + { + title: '/user/login?bar=2 channel contains invalid name with url query parameters: ?bar=2', + location: { + endColumn: 9, + endLine: 6, + endOffset: 96, + jsonPointer: '/channels/~1user~1login?bar=2', + startColumn: 28, + startLine: 5, + startOffset: 87 + } + } + ]); + } + }); + + it('should throw error that single channel definition failed both validations', async function () { + const inputString = `{ + "channels": { + "user/{userId}/signedup?foo=1": { + } + } + }`; + const parsedInput = JSON.parse(inputString); + + try { + validateChannels(parsedInput, inputString, input); + } catch (e) { + expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); + expect(e.title).to.equal('Channel validation failed'); + expect(e.parsedJSON).to.deep.equal(parsedInput); + expect(e.validationErrors).to.deep.equal([ + { + title: 'user/{userId}/signedup?foo=1 channel does not have a corresponding parameter object for: userId', + location: { + endColumn: 9, + endLine: 4, + endOffset: 67, + jsonPointer: '/channels/user~1{userId}~1signedup?foo=1', + startColumn: 40, + startLine: 3, + startOffset: 58 + } + }, + { + title: 'user/{userId}/signedup?foo=1 channel contains invalid name with url query parameters: ?foo=1', + location: { + endColumn: 9, + endLine: 4, + endOffset: 67, + jsonPointer: '/channels/user~1{userId}~1signedup?foo=1', + startColumn: 40, + startLine: 3, + startOffset: 58 + } + } + ]); + } + }); + + it('should throw error that both provided channels contain errors', async function () { + const inputString = `{ + "channels": { + "/user/signedup?foo=1": { + }, + "test/{test}": { + } + } + }`; + const parsedInput = JSON.parse(inputString); + + try { + validateChannels(parsedInput, inputString, input); + } catch (e) { + expect(e.type).to.equal('https://github.com/asyncapi/parser-js/validation-errors'); + expect(e.title).to.equal('Channel validation failed'); + expect(e.parsedJSON).to.deep.equal(parsedInput); + expect(e.validationErrors).to.deep.equal([ + { + title: 'test/{test} channel does not have a corresponding parameter object for: test', + location: { + endColumn: 9, + endLine: 6, + endOffset: 90, + jsonPointer: '/channels/test~1{test}', + startColumn: 22, + startLine: 5, + startOffset: 81 + } + }, + { + title: '/user/signedup?foo=1 channel contains invalid name with url query parameters: ?foo=1', + location: { + endColumn: 9, + endLine: 4, + endOffset: 59, + jsonPointer: '/channels/~1user~1signedup?foo=1', + startColumn: 32, + startLine: 3, + startOffset: 50 + } + } + ]); + } + }); +}); +describe('validateOperationId()', function () { const operations = ['subscribe', 'publish']; - it('should successfully validate operationId', async function() { + it('should successfully validate operationId', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -327,18 +568,18 @@ describe('validateOperationId()', function() { } }`; const parsedInput = JSON.parse(inputString); - + expect(validateOperationId(parsedInput, inputString, input, operations)).to.equal(true); }); - it('should successfully validate if channel object not provided', function() { + it('should successfully validate if channel object not provided', function () { const inputString = '{}'; const parsedInput = JSON.parse(inputString); - + expect(validateOperationId(parsedInput, inputString, input, operations)).to.equal(true); }); - it('should throw error that operationIds are duplicated and that they duplicate', function() { + it('should throw error that operationIds are duplicated and that they duplicate', function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -405,10 +646,10 @@ describe('validateOperationId()', function() { }); }); -describe('validateServerSecurity()', function() { +describe('validateServerSecurity()', function () { const specialSecTypes = ['oauth2', 'openIdConnect']; - it('should successfully validate server security', async function() { + it('should successfully validate server security', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -436,11 +677,11 @@ describe('validateServerSecurity()', function() { } }`; const parsedInput = JSON.parse(inputString); - + expect(validateServerSecurity(parsedInput, inputString, input, specialSecTypes)).to.equal(true); }); - it('should successfully validate if server security not provided', async function() { + it('should successfully validate if server security not provided', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -454,11 +695,11 @@ describe('validateServerSecurity()', function() { } }`; const parsedInput = JSON.parse(inputString); - + expect(validateServerSecurity(parsedInput, inputString, input, specialSecTypes)).to.equal(true); }); - it('should successfully validate server security of special security type like oauth2', async function() { + it('should successfully validate server security of special security type like oauth2', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -488,11 +729,11 @@ describe('validateServerSecurity()', function() { } }`; const parsedInput = JSON.parse(inputString); - + expect(validateServerSecurity(parsedInput, inputString, input, specialSecTypes)).to.equal(true); }); - it('should throw error that server has no security schema provided when components schema object is there but missing proper values', async function() { + it('should throw error that server has no security schema provided when components schema object is there but missing proper values', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -520,7 +761,7 @@ describe('validateServerSecurity()', function() { } }`; const parsedInput = JSON.parse(inputString); - + try { validateServerSecurity(parsedInput, inputString, input, specialSecTypes); } catch (e) { @@ -544,7 +785,7 @@ describe('validateServerSecurity()', function() { } }); - it('should throw error that server has no security schema provided when components schema object is not in the document', async function() { + it('should throw error that server has no security schema provided when components schema object is not in the document', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -565,7 +806,7 @@ describe('validateServerSecurity()', function() { } }`; const parsedInput = JSON.parse(inputString); - + try { validateServerSecurity(parsedInput, inputString, input, specialSecTypes); } catch (e) { @@ -586,10 +827,10 @@ describe('validateServerSecurity()', function() { } } ]); - } + } }); - it('should throw error that server security is not declared as empty array', async function() { + it('should throw error that server security is not declared as empty array', async function () { const inputString = `{ "asyncapi": "2.0.0", "info": { @@ -621,7 +862,7 @@ describe('validateServerSecurity()', function() { } }`; const parsedInput = JSON.parse(inputString); - + try { validateServerSecurity(parsedInput, inputString, input, specialSecTypes); } catch (e) { @@ -654,6 +895,7 @@ describe('validateServerSecurity()', function() { } } ]); - } + } }); -}); \ No newline at end of file +} +); \ No newline at end of file