Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swagger] Specs are valid, when only warnings are shown #4294

Merged
13 changes: 11 additions & 2 deletions services/swagger/swagger.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
calebcartwright marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
21 changes: 21 additions & 0 deletions services/swagger/swagger.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ t.create('Valid')
color: 'brightgreen',
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove any of the mocked tests that are duplicative of the real/live tests. You acn also remove the Live prefix from the test names, as our test runner automatically denotes whether a test is mocked or live in the output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed all mocked ones besides the invalid one

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 =>
Expand Down