Error value.split is not a function when trying to analyze a param serialization with simple style
When I try to analyze with the proxy an array path param with style simple and explode true I get an error TypeError: value.split is not a function.
Context
I cannot validate the array as a param in the request.
Current Behavior
Given this enpoint in a openAPI 3.0.4
/codes/{codeIds}:
get:
tags:
- code
parameters:
- in: path
name: codeIds
required: true
schema:
type: array
items:
type: integer
minimum: 100
maximum: 999
example: 123
minItems: 1
uniqueItems: true
style: simple
explode: false
example: 123,245,345
- name: size
in: query
required: false
description: Number of elemments to return
schema:
type: integer
minimum: 0
example: 10
- name: page
in: query
required: false
description: From where return elements
schema:
type: integer
minimum: 0
example: 0
responses:
'200':
description: Users with that Codes
content:
application/json:
schema:
$ref: '#/components/schemas/Users'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: Unathorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: Not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
When I run the query /codes/123,456?size=5&page=5
Then I got the following error:
[1:24:56 PM] › [HTTP SERVER] get /codes/123,456 ℹ info Request received
/opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/deserializers/style/simple.js:20
return value === '' ? [] : value.split(',');
^
TypeError: value.split is not a function
at deserializeArray (/opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/deserializers/style/simple.js:20:38)
at deserializeSimpleStyle (/opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/deserializers/style/simple.js:9:16)
at /opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/validators/params.js:31:19
at /opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/lodash/lodash.js:13469:38
at /opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/lodash/lodash.js:4967:15
at baseForOwn (/opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/lodash/lodash.js:3032:24)
at mapValues (/opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/lodash/lodash.js:13468:7)
at /opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/prism-http/dist/validator/validators/params.js:27:77
at /opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/fp-ts/lib/Option.js:211:71
at pipe (/opt/homebrew/lib/node_modules/@stoplight/prism-cli/node_modules/fp-ts/lib/function.js:311:35)
Expected Behavior
The proxy should be able to analyze codeIds as an array without an error, and tell me if the style is correct.
Possible Workaround/Solution
I guess is a problem with the value field, probably value is not consider as a string so it doesn't have split() method.
Steps to Reproduce
openapi.yml package-lock.json package.json server.js
- Run the server with
npm run start - Run the proxy with
prism proxy openapi.yml http://localhost:3000 -p 3001 -v trace - Execute curl
curl --location 'http://127.0.0.1:3001/codes/123,456?size=5&page=5' \ --header 'Authorization: Bearer 1234'
Environment
Version used: Prsim 5.14.2 Node version: 24.4.1 Operating System and version (desktop or mobile): Mac 15.5
To give more context: The bug happens in this line.
function deserializeArray(value: string) {
return value === '' ? [] : value.split(',');
}
The issue is that this object value is not a string, so it cannot do the split function. As the test seems to be working and fine (there is a positive case that is the happy path that I'm using), the problem must be in how the field value is filled (which is not covered in the tests), so the problem must be in this line const value = parameters[name];.
I would like to give a more complete answer or even a solution, but I'm not able yet to compile locally the project.
I was able to compile and fix the bug. There were also issues with matrix and label style, I fixed that too.
There were also a second bug in matrix style. In this line it compares the name of the objects with the expected name of the object written in the OpenAPI. The issue is that the OpenAPI name is always in lower case, so if you write it in camelCase, it gives an error.
For example, if I write nameId in the OpenAPI, the name field would be nameid, so when I sent the field in the request as nameId, it returns an error because they are not the same. I was not able to caught were was nameId transform to lowercase, so as a quick fix, I lowercase also the request field.
Also, I would have like to change the way the errors are report by these lines throw new Error('Matrix serialization style requires parameter to be prefixed with ";"');, because it breaks completely the execution. I would have like to change it to a validation level, so its part of the validation and not an exception, but I was unable to find any example of it.