express-jsdoc-swagger icon indicating copy to clipboard operation
express-jsdoc-swagger copied to clipboard

Is it possible to defined array of strings which are enum values?

Open paulish opened this issue 3 years ago • 1 comments

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.

paulish avatar Sep 14 '21 13:09 paulish

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" } }

ogunoz avatar Dec 03 '21 21:12 ogunoz