From f93ea998626b08f565b1dce9ba715b3b4fdc8ec3 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Sat, 2 Nov 2019 19:29:20 +0100 Subject: [PATCH 1/8] when the service responds with only warnings the spec is valid --- services/swagger/swagger.service.js | 13 +++++++++++-- services/swagger/swagger.tester.js | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/services/swagger/swagger.service.js b/services/swagger/swagger.service.js index 7bb5948ffdb78..03f4b22d2c049 100644 --- a/services/swagger/swagger.service.js +++ b/services/swagger/swagger.service.js @@ -61,15 +61,24 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { }, }) } - async handle({ scheme, url }) { const json = await this.fetch({ scheme, urlF: url }) const valMessages = json.schemaValidationMessages - if (!valMessages || valMessages.length === 0) { + if ( + !valMessages || + valMessages.length === 0 || + this.onlyWarnings(valMessages) + ) { return this.constructor.render({ message: 'valid', clr: 'brightgreen' }) } else { return this.constructor.render({ message: 'invalid', clr: 'red' }) } } + + onlyWarnings(valMessages) { + let result = true + valMessages.forEach(msg => (result = msg.level === 'warning' && result)) + return result + } } diff --git a/services/swagger/swagger.tester.js b/services/swagger/swagger.tester.js index 376ec1cda307d..b18877596541f 100644 --- a/services/swagger/swagger.tester.js +++ b/services/swagger/swagger.tester.js @@ -21,6 +21,27 @@ t.create('Valid') color: 'brightgreen', }) +t.create('Valid with Warnings') + .get(getURL) + .intercept(nock => + nock(apiURL) + .get(apiGetURL) + .query(apiGetQueryParams) + .reply(200, { + schemaValidationMessages: [ + { + level: 'warning', + message: 'warning', + }, + ], + }) + ) + .expectBadge({ + label: 'swagger', + message: 'valid', + color: 'brightgreen', + }) + t.create('Invalid') .get(getURL) .intercept(nock => From 019d4923268de98357580f28fe2756166081d360 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Sat, 2 Nov 2019 20:23:02 +0100 Subject: [PATCH 2/8] add transform method, move color selection to render --- services/swagger/swagger.service.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/services/swagger/swagger.service.js b/services/swagger/swagger.service.js index 03f4b22d2c049..8545570cd31ae 100644 --- a/services/swagger/swagger.service.js +++ b/services/swagger/swagger.service.js @@ -45,8 +45,12 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { return { label: 'swagger' } } - static render({ message, clr }) { - return { message, color: clr } + static render({ message }) { + if (message === 'valid') { + return { message, color: 'brightgreen' } + } else { + return { message, color: 'red' } + } } async fetch({ scheme, urlF }) { @@ -61,24 +65,23 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { }, }) } - async handle({ scheme, url }) { - const json = await this.fetch({ scheme, urlF: url }) - const valMessages = json.schemaValidationMessages + transform(valMessages) { if ( !valMessages || valMessages.length === 0 || - this.onlyWarnings(valMessages) + valMessages.forEach(msg => msg.level === 'warning') ) { - return this.constructor.render({ message: 'valid', clr: 'brightgreen' }) + return 'valid' } else { - return this.constructor.render({ message: 'invalid', clr: 'red' }) + return 'invalid' } } - onlyWarnings(valMessages) { - let result = true - valMessages.forEach(msg => (result = msg.level === 'warning' && result)) - return result + async handle({ scheme, url }) { + const json = await this.fetch({ scheme, urlF: url }) + const valMessages = json.schemaValidationMessages + + return this.constructor.render({ message: this.transform(valMessages) }) } } From c302cc1c008556f80b562f37d13d685826004297 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Sat, 2 Nov 2019 20:29:28 +0100 Subject: [PATCH 3/8] replace forEach with every --- services/swagger/swagger.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/swagger/swagger.service.js b/services/swagger/swagger.service.js index 8545570cd31ae..f482ab9b0a84c 100644 --- a/services/swagger/swagger.service.js +++ b/services/swagger/swagger.service.js @@ -70,7 +70,7 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { if ( !valMessages || valMessages.length === 0 || - valMessages.forEach(msg => msg.level === 'warning') + valMessages.every(msg => msg.level === 'warning') ) { return 'valid' } else { From 6801d7c47e99d185941574d1781e7268cd687925 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Sun, 3 Nov 2019 22:10:35 +0100 Subject: [PATCH 4/8] move file extension to query param --- services/swagger/swagger.service.js | 15 ++++++++------- services/swagger/swagger.tester.js | 5 ++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/services/swagger/swagger.service.js b/services/swagger/swagger.service.js index f482ab9b0a84c..4292da840af81 100644 --- a/services/swagger/swagger.service.js +++ b/services/swagger/swagger.service.js @@ -22,7 +22,7 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { static get route() { return { base: 'swagger/valid/2.0', - pattern: ':scheme(http|https)?/:url*', + pattern: ':scheme(http|https)?/:fileExtension(json|yaml)?/:url*', } } @@ -30,12 +30,13 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { return [ { title: 'Swagger Validator', - pattern: ':scheme/:url', + pattern: ':scheme/:fileExtension/:url', staticPreview: this.render({ message: 'valid', clr: 'brightgreen' }), namedParams: { scheme: 'https', + fileExtension: 'json', url: - 'raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded.json', + 'raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded', }, }, ] @@ -53,14 +54,14 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { } } - async fetch({ scheme, urlF }) { + async fetch({ scheme, fileExtension, urlF }) { const url = 'http://validator.swagger.io/validator/debug' return this._requestJson({ url, schema: validatorSchema, options: { qs: { - url: `${scheme}://${urlF}`, + url: `${scheme}://${urlF}.${fileExtension}`, }, }, }) @@ -78,8 +79,8 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { } } - async handle({ scheme, url }) { - const json = await this.fetch({ scheme, urlF: url }) + async handle({ scheme, fileExtension, url }) { + const json = await this.fetch({ scheme, fileExtension, urlF: url }) const valMessages = json.schemaValidationMessages return this.constructor.render({ message: this.transform(valMessages) }) diff --git a/services/swagger/swagger.tester.js b/services/swagger/swagger.tester.js index b18877596541f..b1db69e32a212 100644 --- a/services/swagger/swagger.tester.js +++ b/services/swagger/swagger.tester.js @@ -3,7 +3,10 @@ const getURL = '/https/example.com/example.json.json' const apiURL = 'http://validator.swagger.io' const apiGetURL = '/validator/debug' -const apiGetQueryParams = { url: 'https://example.com/example.json' } +const apiGetQueryParams = { + fileExtension: 'json', + url: 'https://example.com/example', +} const t = (module.exports = require('../tester').createServiceTester()) From 055815ba2e76aa603c5bb03fb070dfd4c8c910f6 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Mon, 4 Nov 2019 00:19:40 +0100 Subject: [PATCH 5/8] add spec not found, moved url to query param, updated version of supported swagger, WIP redirector --- services/swagger/swagger-redirect.service.js | 19 +++++++++++ services/swagger/swagger-redirect.tester.js | 21 ++++++++++++ services/swagger/swagger.service.js | 34 +++++++++++++------- services/swagger/swagger.tester.js | 26 +++++++++++++-- 4 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 services/swagger/swagger-redirect.service.js create mode 100644 services/swagger/swagger-redirect.tester.js diff --git a/services/swagger/swagger-redirect.service.js b/services/swagger/swagger-redirect.service.js new file mode 100644 index 0000000000000..4e3a1bdf3a4b1 --- /dev/null +++ b/services/swagger/swagger-redirect.service.js @@ -0,0 +1,19 @@ +'use strict' + +const { redirector } = require('..') + +module.exports = [ + redirector({ + category: 'other', + name: 'SwaggerUrlRedirect', + route: { + base: 'swagger/valid/2.0', + pattern: ':scheme(http|https)/:url', + }, + transformPath: () => `/swagger/valid/3.0/spec`, + transformQueryParams: ({ scheme, url }) => ({ + url: `${scheme}://${url}`, + }), + dateAdded: new Date('2019-11-03'), + }), +] diff --git a/services/swagger/swagger-redirect.tester.js b/services/swagger/swagger-redirect.tester.js new file mode 100644 index 0000000000000..8ccb9fd9bdae5 --- /dev/null +++ b/services/swagger/swagger-redirect.tester.js @@ -0,0 +1,21 @@ +'use strict' + +const { ServiceTester } = require('../tester') + +const t = (module.exports = new ServiceTester({ + id: 'SwaggerZrlRedirect', + title: 'SwaggerUrlRedirect', + pathPrefix: '/swagger/valid/2.0', +})) + +t.create('swagger') + .get('/https/example.com/example.json', { + followRedirect: false, + }) + .expectStatus(301) + .expectHeader( + 'Location', + `/swagger/valid/3.0/spec?url=${encodeURIComponent( + 'https://example.com/example.json' + )}` + ) diff --git a/services/swagger/swagger.service.js b/services/swagger/swagger.service.js index 4292da840af81..be514a7cf4354 100644 --- a/services/swagger/swagger.service.js +++ b/services/swagger/swagger.service.js @@ -1,7 +1,8 @@ 'use strict' const Joi = require('@hapi/joi') -const { BaseJsonService } = require('..') +const { optionalUrl } = require('../validators') +const { BaseJsonService, NotFound } = require('..') const validatorSchema = Joi.object() .keys({ @@ -14,6 +15,10 @@ const validatorSchema = Joi.object() }) .required() +const queryParamSchema = Joi.object({ + url: optionalUrl.required(), +}).required() + module.exports = class SwaggerValidatorService extends BaseJsonService { static get category() { return 'other' @@ -21,8 +26,9 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { static get route() { return { - base: 'swagger/valid/2.0', - pattern: ':scheme(http|https)?/:fileExtension(json|yaml)?/:url*', + base: 'swagger/valid/3.0', + pattern: 'spec', + queryParamSchema, } } @@ -30,13 +36,11 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { return [ { title: 'Swagger Validator', - pattern: ':scheme/:fileExtension/:url', staticPreview: this.render({ message: 'valid', clr: 'brightgreen' }), - namedParams: { - scheme: 'https', - fileExtension: 'json', + namedParams: {}, + queryParams: { url: - 'raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded', + 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded.json', }, }, ] @@ -54,14 +58,14 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { } } - async fetch({ scheme, fileExtension, urlF }) { + async fetch({ urlF }) { const url = 'http://validator.swagger.io/validator/debug' return this._requestJson({ url, schema: validatorSchema, options: { qs: { - url: `${scheme}://${urlF}.${fileExtension}`, + url: urlF, }, }, }) @@ -74,13 +78,19 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { valMessages.every(msg => msg.level === 'warning') ) { return 'valid' + } else if ( + valMessages.length === 1 && + valMessages[0].level === 'error' && + valMessages[0].message.includes("Can't read from file") + ) { + throw new NotFound({ prettyMessage: 'spec not found' }) } else { return 'invalid' } } - async handle({ scheme, fileExtension, url }) { - const json = await this.fetch({ scheme, fileExtension, urlF: url }) + async handle(_routeParams, { url }) { + const json = await this.fetch({ urlF: url }) const valMessages = json.schemaValidationMessages return this.constructor.render({ message: this.transform(valMessages) }) diff --git a/services/swagger/swagger.tester.js b/services/swagger/swagger.tester.js index b1db69e32a212..8637f11f94ca5 100644 --- a/services/swagger/swagger.tester.js +++ b/services/swagger/swagger.tester.js @@ -1,11 +1,10 @@ 'use strict' -const getURL = '/https/example.com/example.json.json' +const getURL = '/swagger/valid/3.0/spec?url=https://example.com/example.json' const apiURL = 'http://validator.swagger.io' const apiGetURL = '/validator/debug' const apiGetQueryParams = { - fileExtension: 'json', - url: 'https://example.com/example', + url: 'https://example.com/example.json', } const t = (module.exports = require('../tester').createServiceTester()) @@ -65,3 +64,24 @@ t.create('Invalid') message: 'invalid', color: 'red', }) + +t.create('Not found') + .get(getURL) + .intercept(nock => + nock(apiURL) + .get(apiGetURL) + .query(apiGetQueryParams) + .reply(200, { + schemaValidationMessages: [ + { + level: 'error', + message: "Can't read from file https://example.com/example.json", + }, + ], + }) + ) + .expectBadge({ + label: 'swagger', + message: 'spec not found', + color: 'red', + }) From e642c69c1d4a2ff5a8724da58d12d5f29968639b Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Mon, 4 Nov 2019 00:52:02 +0100 Subject: [PATCH 6/8] fix typo --- services/swagger/swagger-redirect.tester.js | 2 +- services/swagger/swagger.tester.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/swagger/swagger-redirect.tester.js b/services/swagger/swagger-redirect.tester.js index 8ccb9fd9bdae5..20cbc93bf0805 100644 --- a/services/swagger/swagger-redirect.tester.js +++ b/services/swagger/swagger-redirect.tester.js @@ -3,7 +3,7 @@ const { ServiceTester } = require('../tester') const t = (module.exports = new ServiceTester({ - id: 'SwaggerZrlRedirect', + id: 'SwaggerUrlRedirect', title: 'SwaggerUrlRedirect', pathPrefix: '/swagger/valid/2.0', })) diff --git a/services/swagger/swagger.tester.js b/services/swagger/swagger.tester.js index 8637f11f94ca5..2f54a3a71c039 100644 --- a/services/swagger/swagger.tester.js +++ b/services/swagger/swagger.tester.js @@ -1,6 +1,6 @@ 'use strict' -const getURL = '/swagger/valid/3.0/spec?url=https://example.com/example.json' +const getURL = '/spec.json?url=https://example.com/example.json' const apiURL = 'http://validator.swagger.io' const apiGetURL = '/validator/debug' const apiGetQueryParams = { From 731f91dd488efff068ac93562b97a7184da37379 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Mon, 4 Nov 2019 15:16:54 +0100 Subject: [PATCH 7/8] fix json redirect, add live tests, add redirecter tests --- services/swagger/swagger-redirect.service.js | 13 ++-- services/swagger/swagger-redirect.tester.js | 28 ++++++++- services/swagger/swagger.service.js | 66 +++++++++----------- services/swagger/swagger.tester.js | 56 ++++++++++++++++- 4 files changed, 117 insertions(+), 46 deletions(-) diff --git a/services/swagger/swagger-redirect.service.js b/services/swagger/swagger-redirect.service.js index 4e3a1bdf3a4b1..954bd131b0365 100644 --- a/services/swagger/swagger-redirect.service.js +++ b/services/swagger/swagger-redirect.service.js @@ -5,15 +5,16 @@ const { redirector } = require('..') module.exports = [ redirector({ category: 'other', - name: 'SwaggerUrlRedirect', + name: 'SwaggerRedirect', route: { base: 'swagger/valid/2.0', - pattern: ':scheme(http|https)/:url', + pattern: ':scheme(http|https)/:url*', + }, + transformPath: () => `/swagger/valid/3.0`, + transformQueryParams: ({ scheme, url }) => { + const suffix = /(yaml|yml|json)$/.test(url) ? '' : '.json' + return { specUrl: `${scheme}://${url}${suffix}` } }, - transformPath: () => `/swagger/valid/3.0/spec`, - transformQueryParams: ({ scheme, url }) => ({ - url: `${scheme}://${url}`, - }), dateAdded: new Date('2019-11-03'), }), ] diff --git a/services/swagger/swagger-redirect.tester.js b/services/swagger/swagger-redirect.tester.js index 20cbc93bf0805..34e017f8af7d0 100644 --- a/services/swagger/swagger-redirect.tester.js +++ b/services/swagger/swagger-redirect.tester.js @@ -8,14 +8,38 @@ const t = (module.exports = new ServiceTester({ pathPrefix: '/swagger/valid/2.0', })) -t.create('swagger') +t.create('swagger json') .get('/https/example.com/example.json', { followRedirect: false, }) .expectStatus(301) .expectHeader( 'Location', - `/swagger/valid/3.0/spec?url=${encodeURIComponent( + `/swagger/valid/3.0.json?specUrl=${encodeURIComponent( 'https://example.com/example.json' )}` ) + +t.create('swagger yml') + .get('/https/example.com/example.yml', { + followRedirect: false, + }) + .expectStatus(301) + .expectHeader( + 'Location', + `/swagger/valid/3.0.svg?specUrl=${encodeURIComponent( + 'https://example.com/example.yml' + )}` + ) + +t.create('swagger yaml') + .get('/https/example.com/example.yaml', { + followRedirect: false, + }) + .expectStatus(301) + .expectHeader( + 'Location', + `/swagger/valid/3.0.svg?specUrl=${encodeURIComponent( + 'https://example.com/example.yaml' + )}` + ) diff --git a/services/swagger/swagger.service.js b/services/swagger/swagger.service.js index be514a7cf4354..636ae1b80d9fb 100644 --- a/services/swagger/swagger.service.js +++ b/services/swagger/swagger.service.js @@ -4,7 +4,7 @@ const Joi = require('@hapi/joi') const { optionalUrl } = require('../validators') const { BaseJsonService, NotFound } = require('..') -const validatorSchema = Joi.object() +const schema = Joi.object() .keys({ schemaValidationMessages: Joi.array().items( Joi.object({ @@ -16,7 +16,7 @@ const validatorSchema = Joi.object() .required() const queryParamSchema = Joi.object({ - url: optionalUrl.required(), + specUrl: optionalUrl.required(), }).required() module.exports = class SwaggerValidatorService extends BaseJsonService { @@ -26,8 +26,8 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { static get route() { return { - base: 'swagger/valid/3.0', - pattern: 'spec', + base: 'swagger/valid', + pattern: '3.0', queryParamSchema, } } @@ -36,10 +36,10 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { return [ { title: 'Swagger Validator', - staticPreview: this.render({ message: 'valid', clr: 'brightgreen' }), + staticPreview: this.render({ status: 'valid' }), namedParams: {}, queryParams: { - url: + specUrl: 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded.json', }, }, @@ -50,49 +50,45 @@ module.exports = class SwaggerValidatorService extends BaseJsonService { return { label: 'swagger' } } - static render({ message }) { - if (message === 'valid') { - return { message, color: 'brightgreen' } + static render({ status }) { + if (status === 'valid') { + return { message: status, color: 'brightgreen' } } else { - return { message, color: 'red' } + return { message: status, color: 'red' } } } - async fetch({ urlF }) { - const url = 'http://validator.swagger.io/validator/debug' + async fetch({ specUrl }) { return this._requestJson({ - url, - schema: validatorSchema, + url: 'http://validator.swagger.io/validator/debug', + schema, options: { qs: { - url: urlF, + url: specUrl, }, }, }) } - transform(valMessages) { - if ( - !valMessages || - valMessages.length === 0 || - valMessages.every(msg => msg.level === 'warning') - ) { - return 'valid' - } else if ( - valMessages.length === 1 && - valMessages[0].level === 'error' && - valMessages[0].message.includes("Can't read from file") - ) { - throw new NotFound({ prettyMessage: 'spec not found' }) - } else { - return 'invalid' + transform({ json, specUrl }) { + const valMessages = json.schemaValidationMessages + if (!valMessages || valMessages.length === 0) { + return { status: 'valid' } + } else if (valMessages.length === 1) { + const { message, level } = valMessages[0] + if (level === 'error' && message === `Can't read from file ${specUrl}`) { + throw new NotFound({ prettyMessage: 'spec not found or unreadable ' }) + } + } + if (valMessages.every(msg => msg.level === 'warning')) { + return { status: 'valid' } } + return { status: 'invalid' } } - async handle(_routeParams, { url }) { - const json = await this.fetch({ urlF: url }) - const valMessages = json.schemaValidationMessages - - return this.constructor.render({ message: this.transform(valMessages) }) + async handle(_routeParams, { specUrl }) { + const json = await this.fetch({ specUrl }) + const { status } = this.transform({ json, specUrl }) + return this.constructor.render({ status }) } } diff --git a/services/swagger/swagger.tester.js b/services/swagger/swagger.tester.js index 2f54a3a71c039..48329c222c72c 100644 --- a/services/swagger/swagger.tester.js +++ b/services/swagger/swagger.tester.js @@ -1,6 +1,7 @@ 'use strict' -const getURL = '/spec.json?url=https://example.com/example.json' +const getURL = '/3.0.json?specUrl=https://example.com/example.json' +const getURLBase = '/3.0.json?specUrl=' const apiURL = 'http://validator.swagger.io' const apiGetURL = '/validator/debug' const apiGetQueryParams = { @@ -23,7 +24,7 @@ t.create('Valid') color: 'brightgreen', }) -t.create('Valid with Warnings') +t.create('Valid with warnings') .get(getURL) .intercept(nock => nock(apiURL) @@ -82,6 +83,55 @@ t.create('Not found') ) .expectBadge({ label: 'swagger', - message: 'spec not found', + message: 'spec not found or unreadable', + color: 'red', + }) + +t.create('Live valid json 2.0') + .get( + `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded.json` + ) + .expectBadge({ + label: 'swagger', + message: 'valid', + color: 'brightgreen', + }) + +t.create('Live valid yaml 3.0') + .get( + `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml` + ) + .expectBadge({ + label: 'swagger', + message: 'valid', + color: 'brightgreen', + }) + +t.create('Live valid with warnings') + .get(`${getURLBase}https://petstore3.swagger.io/api/v3/openapi.json`) + .expectBadge({ + label: 'swagger', + message: 'valid', + color: 'brightgreen', + }) + +// Isn't a spec, but valid json +t.create('Live invalid') + .get( + `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json` + ) + .expectBadge({ + label: 'swagger', + message: 'invalid', + color: 'red', + }) + +t.create('Live not found') + .get( + `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/notFound.yaml` + ) + .expectBadge({ + label: 'swagger', + message: 'spec not found or unreadable', color: 'red', }) From 5257cbb9c424b34828dfaa529de01f20168d5538 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Tue, 5 Nov 2019 10:12:21 +0100 Subject: [PATCH 8/8] fix naming, remove mocked test where live one exist --- services/swagger/swagger.tester.js | 66 +++--------------------------- 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/services/swagger/swagger.tester.js b/services/swagger/swagger.tester.js index 48329c222c72c..3f8749e46ff4e 100644 --- a/services/swagger/swagger.tester.js +++ b/services/swagger/swagger.tester.js @@ -10,41 +10,6 @@ const apiGetQueryParams = { const t = (module.exports = require('../tester').createServiceTester()) -t.create('Valid') - .get(getURL) - .intercept(nock => - nock(apiURL) - .get(apiGetURL) - .query(apiGetQueryParams) - .reply(200, {}) - ) - .expectBadge({ - label: 'swagger', - message: 'valid', - color: 'brightgreen', - }) - -t.create('Valid with warnings') - .get(getURL) - .intercept(nock => - nock(apiURL) - .get(apiGetURL) - .query(apiGetQueryParams) - .reply(200, { - schemaValidationMessages: [ - { - level: 'warning', - message: 'warning', - }, - ], - }) - ) - .expectBadge({ - label: 'swagger', - message: 'valid', - color: 'brightgreen', - }) - t.create('Invalid') .get(getURL) .intercept(nock => @@ -66,28 +31,7 @@ t.create('Invalid') color: 'red', }) -t.create('Not found') - .get(getURL) - .intercept(nock => - nock(apiURL) - .get(apiGetURL) - .query(apiGetQueryParams) - .reply(200, { - schemaValidationMessages: [ - { - level: 'error', - message: "Can't read from file https://example.com/example.json", - }, - ], - }) - ) - .expectBadge({ - label: 'swagger', - message: 'spec not found or unreadable', - color: 'red', - }) - -t.create('Live valid json 2.0') +t.create('Valid json 2.0') .get( `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-expanded.json` ) @@ -97,7 +41,7 @@ t.create('Live valid json 2.0') color: 'brightgreen', }) -t.create('Live valid yaml 3.0') +t.create('Valid yaml 3.0') .get( `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml` ) @@ -107,7 +51,7 @@ t.create('Live valid yaml 3.0') color: 'brightgreen', }) -t.create('Live valid with warnings') +t.create('Valid with warnings') .get(`${getURLBase}https://petstore3.swagger.io/api/v3/openapi.json`) .expectBadge({ label: 'swagger', @@ -116,7 +60,7 @@ t.create('Live valid with warnings') }) // Isn't a spec, but valid json -t.create('Live invalid') +t.create('Invalid') .get( `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json` ) @@ -126,7 +70,7 @@ t.create('Live invalid') color: 'red', }) -t.create('Live not found') +t.create('Not found') .get( `${getURLBase}https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/notFound.yaml` )