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-06-29 09:14:39 +08:00
|
|
|
const models = ['Message', 'Thread', 'File', 'Error', 'SyncbackRequest']
|
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') {
|
|
|
|
return Joi.object().keys({
|
|
|
|
id: Joi.number(),
|
2016-06-29 09:31:36 +08:00
|
|
|
object: Joi.string(),
|
2016-06-19 18:02:32 +08:00
|
|
|
email_address: Joi.string(),
|
2016-06-30 03:02:31 +08:00
|
|
|
provider: Joi.string(),
|
|
|
|
organization_unit: Joi.string(),
|
2016-06-23 05:17:45 +08:00
|
|
|
connection_settings: Joi.object(),
|
|
|
|
sync_policy: Joi.object(),
|
2016-06-29 09:01:43 +08:00
|
|
|
sync_error: Joi.object(),
|
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,
|
|
|
|
}
|