简体   繁体   中英

ArangoDB Joi Foxx mapping to Swagger is incorrect

I define a bean called TestBean on joi syntax. Then defined another bean BeanMethodDocument which uses TestBean schema/bean. Generated Swagger/model ignores this argument, yet an array defined with TestBean works?

The following JOI syntax seems to lose the TestBean definition: "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');

Generated Swagger document shows the arg argument as empty? "arg": {
"type": "object",
"properties": {},
"additionalProperties": false },

According to the JOI documentation ( https://github.com/hapijs/joi/blob/v15.1.0/API.md#objectschema ) The schema function you used there does return the schema of the current object, it does not set it. You can instead of the joi.object() simply use the TestBean like this:

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

in my local tests this work end you end up with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM