express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

$refs in path that are enums cause validator to expect an array

Open djMax opened this issue 1 month ago • 2 comments

Describe the bug When I put a referenced ENUM in a path param, the validator thinks that the param should be an array.

To Reproduce Something like:

in: path
name: namespace
required: true
schema:
  - red
  - white
  - blue

Works. But if you put that enum in "Colors.yaml" and do

in: path
name: namespace
required: true
schema:
  $ref: ./Colors.yaml

somehow, you will get:

required value must be ["array"]

Error: required value must be [\"array\"]\n    at new KeywordCxt (/nodejs/app/node_modules/ajv/dist/compile/validate/index.js:308:23)\n    at keywordCode (/nodejs/app/node_modules/ajv/dist/compile/validate/index.js:462:17)\n    at /nodejs/app/node_modules/ajv/dist/compile/validate/index.js:222:17\n    at CodeGen.code (/nodejs/app/node_modules/ajv/dist/compile/codegen/index.js:439:13)\n    at CodeGen.block (/nodejs/app/node_modules/ajv/dist/compile/codegen/index.js:568:18)\n    at iterateKeywords (/nodejs/app/node_modules/ajv/dist/compile/validate/index.js:219:9)\n    at groupKeywords (/nodejs/app/node_modules/ajv/dist/compile/validate/index.js:200:13)\n    at /nodejs/app/node_modules/ajv/dist/compile/validate/index.js:192:13\n    at CodeGen.code (/nodejs/app/node_modules/ajv/dist/compile/codegen/index.js:439:13)\n    at CodeGen.block (/nodejs/app/node_modules/ajv/dist/compile/codegen/index.js:568:18)

there's a decent amount of infra between spec and error, so I don't know for SURE that it's the validators fault yet.

Expected behavior Should work as a simple type with the ref or inline.

djMax avatar Nov 20 '25 03:11 djMax