Skip to content

Instantly share code, notes, and snippets.

@simon-p-r
Created September 29, 2015 13:48
Show Gist options
  • Save simon-p-r/51b597f54744b36ac94f to your computer and use it in GitHub Desktop.
Save simon-p-r/51b597f54744b36ac94f to your computer and use it in GitHub Desktop.
Joi issue
internals.Schema = Joi.object({
metaSchema: Joi.object().keys({
description: Joi.string(),
type: Joi.string().required().valid('collection', 'definition', 'record'),
base: Joi.alternatives().when('type', {
is: ['record'],
then: Joi.string().required()
}),
jsonSchema: Joi.string(),
name: Joi.string().required(),
version: Joi.number(),
keys: Joi.alternatives().when('type', {
is: ['collection', 'record'],
then: Joi.array().items(Joi.object({
name: Joi.string(),
flds: Joi.object(),
options: Joi.object()
}))
}),
sid: Joi.array()
}).required(),
schema: Joi.object().required(),
methods: Joi.object()
}).required();
internals.AddArray = Joi.array().items(internals.Schema)
internals.SchemaSet = Joi.object({
collections: Joi.object({
}).pattern(/^[a-zA-Z]+$/, internals.Schema),
definitions: Joi.object({
}).pattern(/^[a-zA-Z]+$/, internals.Schema),
records: Joi.object({
}).pattern(/^[a-zA-Z]+$/, internals.Schema)
});
@simon-p-r
Copy link
Author

I would like to validate incoming parameter to check if it is an object as show in internals.schema or if it is either an array of internal.schema objects or an object with keys - collections, definitions and records which will have unknown key names but its value will be the internal.schema object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment