Files
shields/services/swagger/swagger.tester.js
Michael Schmitz 74a5353b6d [Swagger] Specs are valid, when only warnings are shown (#4294)
* when the service responds with only warnings the spec is valid

* add transform method, move color selection to render

* replace forEach with every

* move file extension to query param

* add spec not found, moved url to query param, updated version of supported swagger, WIP redirector

* fix typo

* fix json redirect, add live tests, add redirecter tests

* fix naming, remove mocked test where live one exist
2019-11-05 20:19:09 -06:00

82 lines
1.9 KiB
JavaScript

'use strict'
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 = {
url: 'https://example.com/example.json',
}
const t = (module.exports = require('../tester').createServiceTester())
t.create('Invalid')
.get(getURL)
.intercept(nock =>
nock(apiURL)
.get(apiGetURL)
.query(apiGetQueryParams)
.reply(200, {
schemaValidationMessages: [
{
level: 'error',
message: 'error',
},
],
})
)
.expectBadge({
label: 'swagger',
message: 'invalid',
color: 'red',
})
t.create('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('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('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('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('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',
})