Search code examples
joiarangodb-foxx

ArangoDB Fox syntax error declaring schema argument


I have declared a JOI schema/bean and cannot use that definition when declaring another schema/bean?

I get a syntax error on "arg: joi.object.schema(TestBean).required()" but can declare an array using a schema like: "argArray: joi.array().items(TestBean).required()"

const TestBean = joi.object().required().keys({
  member1: joi.array().items(joi.string().required()),
  member2: joi.number().required()
}).unknown(); // allow additional attributes

const BeanMethodDocument = joi.object().required().keys({
  arg: joi.object.schema(TestBean).required(),
  argArray: joi.array().items(TestBean).required(),
  option: joi.string().valid('Empty','Full','HalfFull','HalfEmpty')
});

I am expecting that I can use pre-defined declarations of schemas. I just need the proper syntax.


Solution

  • You're missing the function call on joi.object.

    const BeanMethodDocument = joi.object().required().keys({
        arg: joi.object().schema(TestBean).required(),
        // ------------^
        argArray: joi.array().items(TestBean).required(),
        option: joi.string().valid('Empty','Full','HalfFull','HalfEmpty')
    });