Query parameter parser fails to parse array parameters correctly
The query parameter parser fails to parse query parameters in array CSV form (e.g. q=1,2,3).
With the following OpenAPI 3.0 parameter definition:
parameters:
- name: id
in: query
description: ID of the customer to fetch
required: true
style: form
explode: false
schema:
type: array
items:
type: integer
and with the request ?id=1,2,3
It generates then following error:
SyntaxError: Unexpected token , in JSON at position 1
at JSON.parse (<anonymous>)
at parseObject (C:\Users\P772381\Work\cm-ods-api\node_modules\swagger-express-middleware\lib\helpers\json-schema.js:501:24)
at JsonSchema.parse (C:\Users\P772381\Work\cm-ods-api\node_modules\swagger-express-middleware\lib\helpers\json-schema.js:92:14)
at parseParameter (C:\Users\P772381\Work\cm-ods-api\node_modules\swagger-express-middleware\lib\param-parser.js:143:35)
at C:\Users\P772381\Work\cm-ods-api\node_modules\swagger-express-middleware\lib\param-parser.js:35:35
at Array.forEach (<anonymous>)
at parseSimpleParams (C:\Users\P772381\Work\cm-ods-api\node_modules\swagger-express-middleware\lib\param-parser.js:30:12)
at Layer.handle [as handle_request] (C:\Users\P772381\Work\cm-ods-api\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\P772381\Work\cm-ods-api\node_modules\express\lib\router\index.js:317:13)
at C:\Users\P772381\Work\cm-ods-api\node_modules\express\lib\router\index.js:284:7 status: undefined, toJSON: [Function: errorToJSON] }
The error is a result of the following line: https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/lib/param-parser.js#L35
req.query[param.name] = parseParameter(param, req.query[param.name], param);
needs to be
req.query[param.name] = parseParameter(param, req.query[param.name], param.schema);
Is there a plan to fix this? This is a problem not just for the array but any type of path parameter validation. I am trying to parse a simple string id and it is always validating it as an integer ID. the fix above mentioned above works.
Thanks.
Swagger Express Middleware does not support OpenAPI 3.0 yet. The code that you pointed out above is for OpenAPI 2.0 (fka "Swagger")
Thanks for quick reply. I was trying this out with OpenApi 3 branch.
From: James Messinger [email protected] Sent: Thursday, February 14, 2019 9:11 PM To: APIDevTools/swagger-express-middleware Cc: Arvind Agarwal; Comment Subject: Re: [APIDevTools/swagger-express-middleware] Query parameter parser fails to parse array parameters correctly (#116)
Swagger Express Middleware does not support OpenAPI 3.0 yet. The code that you pointed out above is for OpenAPI 2.0 (fka "Swagger")
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/APIDevTools/swagger-express-middleware/issues/116#issuecomment-463674780, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIDgW-DLvX6005VUw3fzT8F-C-IMbPtuks5vNYOogaJpZM4V08uD.
The OpenAPI 3 branch is not yet working and is in a state of active development. We will notify once it is ready for use.
Thanks for your quick responses. I will look forward to the release.
From: Randall Krauskopf [email protected] Sent: Thursday, February 14, 2019 10:52 PM To: APIDevTools/swagger-express-middleware Cc: Arvind Agarwal; Comment Subject: Re: [APIDevTools/swagger-express-middleware] Query parameter parser fails to parse array parameters correctly (#116)
The OpenAPI 3 branch is not yet working and is in a state of active development. We will notify once it is ready for use.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/APIDevTools/swagger-express-middleware/issues/116#issuecomment-463714087, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIDgW1g10iJQVyA0uQ7VORJ5DbkDIkO4ks5vNZthgaJpZM4V08uD.