express-jsdoc-swagger
express-jsdoc-swagger copied to clipboard
Is it possible to defined array of strings which are enum values?
Hello.
In my API I have a request which requires to pass param/property which is array of enum elements. To defined I used the following annotation
/**
* @typedef {object} SomeRequest
* @property {array<string>} typeFilter - Type filter. Can contain multiple values
*/
The problem is that I see no way to constraint array strings by enum as it is possible with regular string properties.
If I add - enum:type1,type2
after the typeFilter
description then enum is applied to array (correct but not desired result).
If I replace my declaration with the following:
/**
* @typedef {string} TypeFilter - Type filter - enum:type1,type2
*/
/**
* @typedef {object} SomeRequest
* @property {array<TypeFilter>} typeFilter - Type filter. Can contain multiple values
*/
then I get array of object in the resulting schema.
I also faced this issue and cannot obtain what I desired directly. Even though it is not the cleanest solution, - json option worked to get the correct openapi value for me.
* @param {object} typeFilter.query - Type filter. Can contain multiple values - json:{"type":"array", "items": { "enum":["type1","type2","type3"],"type":"string" } }