hapi-swaggered icon indicating copy to clipboard operation
hapi-swaggered copied to clipboard

Cannot display array with multiple items in Responses or Request Models

Open jlouthan opened this issue 8 years ago • 0 comments

First of all thank you for this module! I am really liking it so far but have run into one issue. I have the following schema

var firstObj = Joi.object({
    prop1: Joi.string().only('apple').required(),
    prop2: Joi.string().only('banana').required()
}).required();

var secondObj = Joi.object({
    prop1: Joi.number().required()
}).required();

var userId = Joi.string().only('userId').required();

var batchResponse = Joi.array().items(firstObj, secondObj, userId);

and am including it as my response using the plugin way with schema:

config: {
    plugins: {
        'hapi-swaggered': {
            responses: batchResponse
        }
    }
}

Since this models an array with three Joi objects that are each required, I would expect the Response Model schema in the docs to look something like

[
  {
    "prop1": "apple",
    "prop2": "banana",
    "prop3": "Each response object will vary depending on the requests submitted"
  },
  {
    "prop1": 0
  },
  "userId": "userId"
]

But that's not the case. What shows up in the docs instead is

[
  "string"
]

Am I missing something here? I can get one object to appear in the Response Model array if I remove the required() from the array item models, but still cannot figure out how to display an array containing multiple Joi objects in the Response Schema. Is there a way to do this?

I am using the most current versions of hapi-swaggered (2.6.0), hapi-swaggered-ui (2.3.1), and joi (8.0.5)

Thank you very much!!

jlouthan avatar Mar 30 '16 18:03 jlouthan