Last active
February 28, 2018 15:14
-
-
Save jvarness/d69ffb587aad4738fb8c6493113da00a to your computer and use it in GitHub Desktop.
Joi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate(api) { | |
const schema = Joi.object({ | |
paths: Joi.object().pattern( | |
/.+/i, | |
Joi.object().pattern( | |
/.+/i, | |
Joi.object({ | |
parameters: Joi.array().items( | |
Joi.object({ | |
in: Joi.string().valid('header').required(), | |
name: Joi.string().valid('Custom-Required-Header').required(), | |
description: Joi.string().required(), | |
required: Joi.boolean().valid(true).required(), | |
type: Joi.string().valid('string').required(), | |
}).required().label('Missing Custom-Required-Header definition, or it's defined incorrectly'), | |
Joi.object().keys({ | |
name: Joi.string().regex(/^.+id$/ig, 'IDs'), | |
type: Joi.string().invalid('string'), | |
}).unknown().forbidden() | |
.label('IDs must be Strings'), | |
), | |
}), | |
), | |
), | |
}); | |
return Joi.validate(api, schema, { allowUnknown: true, abortEarly: false }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment