joi

AQL- expected join possible in Arangodb and How?

血红的双手。 提交于 2020-01-21 10:17:06
问题 My Environment ArangoDB Version: 3.5.2(the latest i think) Storage Engine:RocksDB Deployment Mode:Single Server Deployment Strategy: Manual Start Infrastructure:own Operating System: Ubuntu 16.04 Total RAM in your machine: 8GB Disks in use: 256GB Problem : I have 2 collection and i have to perform join and want expected result is that possible in Arangodb ?? collection 1 :[ { id :1 , name: "jack" }, { id :2 , name: "ryan" }, { id :3 , name: "sam" }, { id :4 , name: "rick" }, { id :5 , name:

Joi multiple when condition

我怕爱的太早我们不能终老 提交于 2020-01-03 04:38:24
问题 I want to do a validation with Joi in my body, but it seems never work and fall all the time in the same condition. So if i POST with this endPoint: /elasticSearch?eType=scroll&scroll=1h Body:{} that supposed to throw an error, because eType is scroll and in this case scroll_id need to be required,not null, not empty. even when i POST with this endPoint: /elasticSearch?eType=search&scroll=1h Body:{} that supposed to throw an error, because eType is search and in this case query need to be

Node.js + Joi how to display a custom error messages?

北慕城南 提交于 2019-12-29 18:39:23
问题 It seems pretty straight forward to validate user's input in Node.js RESTapi with Joi . But the problem is that my app is not written in English. That means I need to send a custom written messages to the frontend user. I have googled for this and only found issues. Maybe could someone give a solution for this? This is the code I am using to validate with the Joi system: var schema = Joi.object().keys({ firstName: Joi.string().min(5).max(10).required(), lastName: Joi.string().min(5).max(10)

object.pattern() is not working correctly inside array.items() in Joi

此生再无相见时 提交于 2019-12-24 22:25:07
问题 I am trying to validate nested object whose keys should match with outer objects another key whose value is array using Joi I tried to use object.pattern and array.length which is demonstrated at How to validate nested object whose keys should match with outer objects another key whose value is array using Joi? But that is not working with array.items() var object = { details:[{ key1: 'someValue', key2: 'someValue', key3: 'someValue' },{ key1: 'someValue', key2: 'someValue', key3: 'someValue'

validating sub-params dependent on parent params with Joi and Hapi

放肆的年华 提交于 2019-12-24 09:36:24
问题 How can I implement validation for something like the following logic for query params: if (type is 'image') { subtype is Joi.string().valid('png', 'jpg') else if (type is 'publication') { subtype is Joi.string().valid('newspaper', 'book') to get either server/?type=image&subtype=png or server/?type=publication&subtype=book but not both image and publication at the same time? Update: I tried the following code but no luck type: Joi .string() .valid('image', 'publication', 'dataset') .optional

Joi circular dependency error with when condition

限于喜欢 提交于 2019-12-24 06:53:29
问题 I have 3 query parameters longitude , latitude , and radius . I have 3 possible condition: radius - empty, longitude and latitude with some value all 3 parameters with value all 3 parameters empty In all other cases send validation error. e.g. longitude =3.12 - error latitude =2.12, radius =3.2 - error longitude =12.12, latitude =2.12 - ok My schema look like this one: const schema = Joi.object().keys({ longitude: Joi.number().optional().error(new Error('LBL_BAD_LONGITUDE')) .when('latitude',

Validating an array's length against another array's length using joi

自作多情 提交于 2019-12-24 01:03:43
问题 Is there a way to validate that two arrays need to have the same length using joi? Here's an example: Joi.object().keys({ firstNames: Joi.array().items(Joi.string()).single(), lastNames: Joi.array().items(Joi.string()).single(), }); If that was to work, it should also match both array's length so no firstName lacks a lastName . Thanks for the help! 回答1: There certainly is, take a look at .assert(). You can use it to compare the values or attributes of two properties in your object. For your

Striping unknown keys when validating with Joi

元气小坏坏 提交于 2019-12-23 16:52:50
问题 I'm using Joi to validate a JavaScript object in the server. The schema is like the following: var schema = Joi.object().keys({ displayName: Joi.string().required(), email: Joi.string().email(), enabled: Joi.boolean().default(false, "Default as disabled") }).unknown(false); The schema above will report an error if there is an unknown key in the object, which is expected, but what I want is to strip all the unknown silently, without an error. Is it possible to be done? 回答1: You need to use the

How to use enum values with Joi String validation

风格不统一 提交于 2019-12-21 03:51:04
问题 I am using Joi validator for my HTTP requests. There I have a parameter called type . I need to make sure that the possible values for the parameter are either "ios" or "android". How can I do that? body : { device_key : joi.string().required(), type : joi.string().required() } 回答1: You can use valid . const schema = Joi.object().keys({ type: Joi.string().valid('ios', 'android'), }); const myObj = { type: 'none' }; const result = Joi.validate(myObj, schema); console.log(result); This gives an

How to validate array of objects using Joi?

半城伤御伤魂 提交于 2019-12-18 18:36:52
问题 I am getting an array of objects to backend, where each object contains a service name. The structure looks like below [{"serviceName":"service1"}, {"serviceName":"service2"},..] when I get the array at backend, I want to validate that every object in the array has serviceName property. I had written the following code, but even though I pass valid array, I am getting validation error. var Joi = require('joi'); var service = Joi.object().keys({ serviceName: Joi.string().required() }); var