ArangoDB Joi Foxx 映射到 Swagger 不正确

ArangoDB Joi Foxx mapping to Swagger is incorrect

我在 joi 语法上定义了一个名为 TestBean 的 bean。然后定义了另一个使用 TestBean schema/bean 的 bean BeanMethodDocument。生成的 Swagger/model 忽略此参数,但使用 TestBean 定义的数组有效吗?

以下 JOI 语法似乎丢失了 TestBean 定义:"arg: joi.object().schema(TestBean).required(),"

'use strict';
var createRouter = require('@arangodb/foxx/router');
var joi = require('joi');
var router = createRouter();

module.context.use(router);

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

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')
});


router.post('/beanMethod', function (req, res) {
    const arg = req.body.arg;
    const argArray = req.body.argArray;
    const option = req.body.option;

    res.send({result:true});
})
    .body(BeanMethodDocument, 'beanMethod POST request')
    .response(joi.boolean().required(), 'beanMethod POST response')
    .summary('beanMethod summary')
    .description('beanMethod description');

生成的 Swagger 文档显示 arg 参数为空? "arg":{
"type": "object",
"properties":{},
"additionalProperties": 错误 },

根据 JOI 文档 (https://github.com/hapijs/joi/blob/v15.1.0/API.md#objectschema) 您在那里使用的模式函数 return 当前对象的模式,它没有设置它。您可以像这样简单地使用 TestBean 而不是 joi.object():

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

在我的本地测试中,这项工作最终会得到:

{
  "arg": {
    "member1": [
      "string"
    ],
    "member2": 0
  },
  "argArray": [
    {
       "member1": [
         "string"
       ],
       "member2": 0
    }
  ],
  "option": "Empty"
}