Array query parameter #196
Replies: 12 comments 3 replies
This comment has been hidden.
This comment has been hidden.
-
It is a bit strange because the same workflow you have provided results me in different output than yours: This is usually interpreted as single string This is the complete workflow I used for this test
And Step CI version is 2.7.2 |
Beta Was this translation helpful? Give feedback.
-
The main problem is when you specify a single element array. The fact is when a workflow is built using a single array parameter, Step CI make the request and the resulting URL may cause validation errors in the API. Because it is waiting for an array but a single string value is received. I know there are many ways to represent arrays in a query string and some of them are ambiguous when there are a single element only. This is an example of how express.js parse url query parameters
I debugged the application and I see that the parameter searchString is passed as This point to the possible solution commented here sindresorhus/got#1559 (comment) to use like
I am not writing the workflow manually, it is generated by plugin-openapi that uses params |
Beta Was this translation helpful? Give feedback.
-
Would you be able to contribute a fix? |
Beta Was this translation helpful? Give feedback.
-
Sure, I will work in a PR |
Beta Was this translation helpful? Give feedback.
-
My example above was incorrect http:
url: /filter
method: GET
params:
fruits:
- apple
- banana produces:
while this: http:
url: /filter
method: GET
params:
-
- 'fruits'
- 'apple'
-
- 'fruits'
- 'banana' produces:
|
Beta Was this translation helpful? Give feedback.
-
Here's a less weirder way to express the above params:
- ['fruits', 'apples']
- ['fruits', 'bananas'] |
Beta Was this translation helpful? Give feedback.
-
Will reopen it as the issue still exists |
Beta Was this translation helpful? Give feedback.
-
My two cents: I don't think the syntax 'parameter[]' should be considered correct because it is not a standard syntax. Instead, it's just a common way to represent arrays. Even though it is natively supported by some languages/frameworks, like PHP, it doesn't necessarily mean that every framework follows this convention. I believe a better way to handle this would be to explicitly add the brackets in the parameter name in the YAML. So, following the example @mishushakov provided, it may look like this: params:
- ['fruits[]', 'apples']
- ['fruits[]', 'bananas'] |
Beta Was this translation helpful? Give feedback.
-
Agree with @alenaksu fully. Moved to discussions for now |
Beta Was this translation helpful? Give feedback.
-
I agree with @alenaksu, the |
Beta Was this translation helpful? Give feedback.
-
However I also agree with @javier-sierra-sngular in saying that |
Beta Was this translation helpful? Give feedback.
-
What happened?
The query parameter of type array is not transformed into an array in the request URL.
[GET] /?singleParameter=true&arrayParameter=true
- Incorrect[GET] /?singleParameter=true&arrayParameter[]=true
- CorrectWhat did you expect to happen?
If the value is of type array, the URL should contains the appropiate syntax to indicate it.
Version
2.7.2
Environment
Node v18.18.0
How can we reproduce this bug?
Using this workflow will result in the request
[GET] /?singleParameter=true&arrayParameter=true
, where arrayParameter is not an array as specified in the workflowRelevant log output
No response
Would you be interested in working on a bugfix for this issue?
Beta Was this translation helpful? Give feedback.
All reactions