How to use the object function from joi
Find comprehensive JavaScript joi.object code examples handpicked from public code repositorys.
332 333 334 335 336 337 338 339 340 341 342
* @param {Object} obj * @return {Object} */ utilities.toJoiObject = function(obj) { if (!utilities.isJoi(obj) && utilities.isObject(obj)) { return Joi.object(obj); } return obj; };
427
901
27
22 23 24 25 26 27 28 29 30
const resultModel = Joi.object({ equals: Joi.number() }).label('Result'); const errorModel = Joi.object({ code: Joi.number(), msg: Joi.string() }).label('Error');
425
901
27
+ 27 other calls in file
GitHub: mozilla/fxa
44 45 46 47 48 49 50 51 52 53
method: 'POST', path: '/password/change/start', options: { ...PASSWORD_DOCS.PASSWORD_CHANGE_START_POST, validate: { payload: isA.object({ email: validators.email().required().description(DESCRIPTION.email), oldAuthPW: validators.authPW.description(DESCRIPTION.authPW), }), },
206
481
43
+ 12 other calls in file
GitHub: Twipped/joi-to-swagger
342 343 344 345 346 347 348 349 350
// inspect(schema); if (!schema) throw new Error('No schema was passed.'); if (isPlainObject(schema)) { schema = joi.object().keys(schema); } if (!joi.isSchema(schema)) throw new TypeError('Passed schema does not appear to be a joi schema.');
61
154
0
+ 4 other calls in file
GitHub: ustaxcourt/ef-cms
779 780 781 782 783 784 785 786 787 788 789 790
), }; joiValidationDecorator( Case, joi.object().keys(Case.VALIDATION_RULES), Case.VALIDATION_ERROR_MESSAGES, ); /**
36
72
19
+ 3 other calls in file
GitHub: ustaxcourt/ef-cms
242 243 244 245 246 247 248 249 250 251
otherwise: joi.optional().allow(null), then: joi.required(), }, ), statistics: Case.VALIDATION_RULES.statistics, stinFile: joi.object().optional(), // object of type File stinFileSize: JoiValidationConstants.MAX_FILE_SIZE_BYTES.when('stinFile', { is: joi.exist().not(null), otherwise: joi.optional().allow(null), then: joi.required(),
36
72
19
+ 19 other calls in file
68 69 70 71 72 73 74 75 76 77
const configJoi = joi.object({ zookeeper: joi.object({ connectionString: joi.string().required(), }).when('kafka.backlogMetrics', { is: joi.exist(), then: joi.required() }), kafka: joi.object({ hosts: joi.string().required(), backlogMetrics: { zkPath: joi.string().required(), intervalS: joi.number().default(60),
18
51
60
+ 15 other calls in file
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
}) ) .unique((a, b) => a.name === b.name), timelineTemplateId: Joi.string(), // Joi.optionalId(), phases: Joi.array().items( Joi.object().keys({ phaseId: Joi.id(), duration: Joi.number().integer().min(0), constraints: Joi.array() .items(
44
17
25
+ 26 other calls in file
GitHub: yoitsro/joigoose
305 306 307 308 309 310 311 312 313 314
let joiSchema = Hoek.clone(originalJoiSchema); if (joiSchema._isObjectId) { joiSchema = Joi.alternatives( joiSchema, Joi.object().instance(internals.mongoose.Types.ObjectId) ); } try {
22
180
0
+ 3 other calls in file
203 204 205 206 207 208 209 210 211 212
).optional(), freeText: JoiValidationConstants.STRING.optional(), hasSupportingDocuments: joi.boolean().required(), lodged: joi.boolean().optional(), ordinalValue: JoiValidationConstants.STRING.optional(), previousDocument: joi.object().optional(), primaryDocumentFile: joi.object().required(), primaryDocumentFileSize: joi .number() .optional()
35
72
19
+ 5 other calls in file
13 14 15 16 17 18 19 20 21 22
password: Joi.string().min(Constants.PASSWORD_MIN_LENGTH).max(Constants.PASSWORD_MAX_LENGTH).required(), }); validateLoginInput = (loginData) => loginSchema.validate(loginData); const registerShema = Joi.object({ name: Joi.string().min(Constants.NAME_MIN_LENGTH).max(Constants.NAME_MAX_LENGTH).required(), email: Joi.string().min(Constants.EMAIL_MIN_LENGTH).max(Constants.EMAIL_MAX_LENGTH).email().required(), password: Joi.string().min(Constants.PASSWORD_MIN_LENGTH).max(Constants.PASSWORD_MAX_LENGTH).required(), confirmPassword: Joi.string().required().valid(Joi.ref('password')),
15
40
0
+ 11 other calls in file
GitHub: adobe/aio-tvm
155 156 157 158 159 160 161 162 163 164
* @returns {joi.ValidationResult} joi * @memberof Tvm * @private */ _validateRequestParams (params) { return joi.object().label('params').keys(this._validationSchema) .required() .pattern(/^$/, joi.any()).pattern(/^__ow_.+$/, joi.any()) // this means allow all unknown parameters that start with __ow_ and '' .validate(params) }
11
10
22
159 160 161 162 163 164 165 166 167 168
> 它可能会将其他人从上小时的故障排查中解救 ```js const joi = require('joi') const envVarsSchema = joi.object({ NODE_ENV: joi.string() .valid(['development', 'production', 'test', 'provision']) .required(), PORT: joi.number()
5
22
3
93 94 95 96 97 98 99 100 101 102 103
} }); router.get("/:cohort", passport.authenticate(["referent", "young"], { session: false, failWithError: true }), async (req, res) => { try { const { error, value } = Joi.object({ cohort: Joi.string().required(), }) .unknown() .validate(req.params, { stripUnknown: true });
4
9
0
+ 4 other calls in file
216 217 218 219 220 221 222 223 224
if (error) { capture(error); return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS }); } const { errorBody } = Joi.object({ options: Joi.object().allow(null, {}), }).validate({ ...req.body }, { stripUnknown: true }); if (errorBody) return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS });
4
9
0
+ 7 other calls in file
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
const young = await YoungModel.findById(req.params.id); if (!young) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND }); let value; if (["imageRight"].includes(document)) { const { error: bodyError, value: tempValue } = Joi.object({ [`${document}FilesStatus`]: Joi.string() .trim() .valid(FILE_STATUS_PHASE1.TO_UPLOAD, FILE_STATUS_PHASE1.WAITING_VERIFICATION, FILE_STATUS_PHASE1.WAITING_CORRECTION, FILE_STATUS_PHASE1.VALIDATED) .required(),
4
8
4
+ 227 other calls in file
65 66 67 68 69 70 71 72 73 74
var json = lodash_1.cloneDeep(_json); if (Utils_1.isObject(json) && "then" in json) return translateWhen(json); if (!Utils_1.isObject(json) || !("type" in json)) return json; var validation = json.type === "object" ? Joi.object(Utils_1.propertiesToJson(json.properties)) : Joi[json.type || "any"](); var _loop_1 = function (k) { var _a, _b; switch (k) { case "type":
3
12
0
+ 3 other calls in file
10 11 12 13 14 15 16 17 18 19 20
const previousPath = `${urlPrefix}/summer-abstraction-mains` const { WATER_SOURCE, UNSUSTAINABLE_WATER_SOURCE } = require('../helpers/water-source-data') let waterSourceArray = [] let waterSourcePlannedArray = [] const schema = Joi.object({ waterSourceCurrent: Joi.array().single().required().custom((value, helper) => { waterSourceArray = value.filter((item) => UNSUSTAINABLE_WATER_SOURCE.includes(item)) return value }),
2
3
0
0 1 2 3 4 5 6 7 8 9 10 11
const Joi = require('joi'); const isOnlyLetters = /(^[а-яА-ЯёЁa-zA-ZЇїІіЄєҐґ ]+$)/u; const isEmpty = /[\S\s]+[\S]+/; const addSchema = Joi.object({ transactionType: Joi.boolean().required().messages({ 'boolean.base': `{{#label}} should be a type of boolean`, 'any.required': `{{#label}} is a required field`, }),
2
2
0
joi.string is the most popular function in joi (40578 examples)