2016-06-19 18:02:32 +08:00
|
|
|
const Joi = require('joi');
|
|
|
|
|
|
|
|
function replacer(key, value) {
|
|
|
|
// force remove any disallowed keys here
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function jsonSchema(modelName) {
|
2016-07-09 07:53:01 +08:00
|
|
|
const models = ['Message', 'Thread', 'File', 'Error', 'SyncbackRequest', 'Account']
|
2016-06-29 04:55:00 +08:00
|
|
|
if (models.includes(modelName)) {
|
|
|
|
return Joi.object();
|
|
|
|
}
|
2016-06-19 18:02:32 +08:00
|
|
|
if (modelName === 'Account') {
|
2016-07-09 07:53:01 +08:00
|
|
|
// Ben: Disabled temporarily because folks keep changing the keys and it's hard
|
|
|
|
// to keep in sync. Might need to consider another approach to these.
|
|
|
|
// return Joi.object().keys({
|
|
|
|
// id: Joi.number(),
|
|
|
|
// object: Joi.string(),
|
|
|
|
// email_address: Joi.string(),
|
|
|
|
// provider: Joi.string(),
|
|
|
|
// organization_unit: Joi.string(),
|
|
|
|
// connection_settings: Joi.object(),
|
|
|
|
// sync_policy: Joi.object(),
|
|
|
|
// sync_error: Joi.object().allow(null),
|
|
|
|
// first_sync_completed_at: Joi.number().allow(null),
|
|
|
|
// last_sync_completions: Joi.array(),
|
|
|
|
// })
|
2016-06-23 05:17:45 +08:00
|
|
|
}
|
2016-07-01 00:29:21 +08:00
|
|
|
if (modelName === 'Folder') {
|
|
|
|
return Joi.object().keys({
|
|
|
|
id: Joi.number(),
|
|
|
|
object: Joi.string(),
|
|
|
|
account_id: Joi.string(),
|
|
|
|
name: Joi.string().allow(null),
|
|
|
|
display_name: Joi.string(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (modelName === 'Label') {
|
2016-06-23 05:17:45 +08:00
|
|
|
return Joi.object().keys({
|
|
|
|
id: Joi.number(),
|
2016-06-29 09:31:36 +08:00
|
|
|
object: Joi.string(),
|
2016-06-30 01:36:32 +08:00
|
|
|
account_id: Joi.string(),
|
2016-06-23 05:17:45 +08:00
|
|
|
name: Joi.string().allow(null),
|
|
|
|
display_name: Joi.string(),
|
2016-06-19 18:02:32 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function jsonStringify(models) {
|
|
|
|
return JSON.stringify(models, replacer, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
jsonSchema,
|
|
|
|
jsonStringify,
|
|
|
|
}
|