-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array[number] query params is NOT correctly parsed. #5793
Comments
Hi @shamisonn, thanks for the detailed issue! There seems to be 3 issues here: 1. Param array coercion does not work
I've managed to replicate the issue from my end with the sandbox. 2. Accidental nested array
For example, the generated OAS3 spec from the sandbox is: ...
"parameters": [
{
"name": "numberArray",
"in": "query",
"schema": {
"type": "array",
"items": {
"description": "number array",
"items": {
"type": "number",
"pattern": "[0-9]{4}"
}
}
}
},
{
"name": "stringArray",
"in": "query",
"schema": {
"type": "array",
"items": {
"description": "string array",
"items": {
"type": "string",
"pattern": "[a-zA-Z]{4}"
}
}
}
}
],
... Notice the nested To resolve, we can remove the @param.array('numberArray', 'query', {
description: 'number array',
- items: {
type: 'number',
pattern: '[0-9]{4}',
- },
})
numberArray: number[],
@param.array('stringArray', 'query', {
description: 'string array',
- items: {
type: 'string',
pattern: '[a-zA-Z]{4}',
- },
})
stringArray: string[], This would result in the following OAS3 spec: ...
"parameters": [
{
"name": "numberArray",
"in": "query",
"schema": {
"type": "array",
"items": {
"description": "number array",
"type": "number",
"pattern": "[0-9]{4}"
}
}
},
{
"name": "stringArray",
"in": "query",
"schema": {
"type": "array",
"items": {
"description": "string array",
"type": "string",
"pattern": "[a-zA-Z]{4}"
}
}
}
],
... Notice that there's no more nested This, however, does not resolve the first issue. This also reveals a third issue: 3. Certain properties are placed in
|
thank you for early reply!
oh, I'll fix the sandbox. thank you for details. (edited at 2020/06/20) fixed sandbox => shamisonn/reproduce-lb4-bug-oas-array@d7bd2bd |
Thank you @achrinza and @shamisonn Good catch. This is loosely related to the story I am fixing in #4992 Let me summarize the bug here. I tried with Explorer inputs, not working either. DescriptionParsing array value from argument decorated by Given controller method async helloArrayParse(
@param.array("numberArray", "query", {
type: "number",
pattern: "[0-9]{4}",
}) numberArray: number[],
@param.array("stringArray", "query", {
type: "string",
pattern: "[a-zA-Z]{4}",
}) stringArray: string[],
): Promise<object> {
return {
numberArray: numberArray,
stringArray: stringArray,
};
} Current BehaviourProvide some number inputs for the first array param The returned data is not coerced to number, but a string instead. Expected Behaviour{
"numberArray": [
// DIFFERENCE: The values should be numbers instead of strings.
12345,
123
],
"stringArray": [
"12345",
"123"
]
} |
There is another issue I noticed that if you only pass one value e.g. I also noticed that Seems like there is a general issue with the |
Also notice the same issue as you mention. |
This one is resolved. I tried to reproduce the issue above and am not getting it. Will have a look again |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Steps to reproduce
I create HelloController, it can get request parameters by array query strings
/hello_array_parse
/hello_comma_parse
style: 'form', explode: false
In detail: https://github.com/shamisonn/reproduce-lb4-bug-oas-array
Current Behavior
case1: request query by array params
request for
/hello_array_parse
response
case2: request query by array params which delimited by comma
request for
/hello_comma_parse
response
Expected Behavior
both of case1 and case2 are same expected like below, if pattern option is nothing.
I expected
numberArray
is parsed type of array[number].if pattern is there, expected error.
Link to reproduction sandbox
In guideline, Modify the selected example project. but I wrote by orginal.
if you ok, check my original example.
Additional information
I don't have one myself, but I was hoping we could implement it here: https://github.com/strongloop/loopback-next/blob/master/packages/rest/src/coercion/coerce-parameter.ts#L58-L81
like this:
Related Issues
I can't find. if duplicate , close this.
Thank you for reading!
See Reporting Issues for more tips on writing good issues
Acceptance Criteria
The text was updated successfully, but these errors were encountered: