Dictionary with unknown string of characters for key and array of strings as value in Joi and Node

I'm trying to right a validation wrapper for one of my Node services. The JSON object has a Dictionary that has keys which do not have a standard value, and the value is a array of one or more strings. Here is an example of my JSON object?

     "IncomingId" : "Id1",
     "LoginId": "Id2",
     "FirstName" : "Name1",
     "MiddleName" : "Name2",
     "LastName" : "Name3",
     "Questions" : {
       "Who are you?" : [
         "I am me."

IncomingId is required, while they need to either provide:

  1. the First Name/Middle Name/Last Name fields, or,

  2. can just provide the LoginId field on its own.

Also the Questions field is required. Unsure how to do an OR on those fields, and also check if the Dictionary is matching the proper field. This is what I have written so far, and it does not work:

securityChallenge: {
    body: {
        IncomingId: Joi.string().required(),
        LoginId: Joi.string(),
        FirstName: Joi.string(),
        MiddleName: Joi.string(),
        LastName: Joi.string(),
        Questions: Joi.object({
            arg: Joi.string().min(1).required(),
            value: Joi.array().items(Joi.string()).min(1).required()

1 answer