Files
shields/services/validators.js
Paul Melnikow 6a737b7b38 Rewrite the DynamicJson badge (#2399)
This starts the rewrite of the dynamic badges. I've pulled into BaseService an initial version of the query param validation from #2325.

I've extended from BaseJsonService to avoid duplicating the deserialization logic, though it means there is a bit of duplicated code among the three dynamic services. The way to unravel this would be to move the logic from `_requestJson` and friends from the base classes into functions so DynamicJson can inherit from BaseDynamic. Would that be worth it?

This introduces a regression of #1446 for this badge.

Close #2345
2018-12-06 16:45:40 -05:00

23 lines
472 B
JavaScript

'use strict'
const Joi = require('joi').extend(require('joi-extension-semver'))
module.exports = {
nonNegativeInteger: Joi.number()
.integer()
.min(0)
.required(),
anyInteger: Joi.number()
.integer()
.required(),
semver: Joi.semver()
.valid()
.required(),
// TODO This accepts URLs with query strings and fragments, which for some
// purposes should be rejected.
optionalUrl: Joi.string().uri({ scheme: ['http', 'https'] }),
}