moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
292 stars 120 forks source link

Query string number params are not converted #305

Closed alvaroinckot closed 2 years ago

alvaroinckot commented 2 years ago

Following the sample math.service.js and calling it http://0.0.0.0:3000/math/mult?a=1&b=2 returns a validation error:

{"name":"ValidationError","message":"Parameters validation error!","code":422,"type":"VALIDATION_ERROR","data":[{"type":"number","message":"The 'a' field must be a number.","field":"a","actual":"1","nodeID":"mac-542187-70487","action":"math.mult"},{"type":"number","message":"The 'b' field must be a number.","field":"b","actual":"2","nodeID":"mac-542187-70487","action":"math.mult"}]}

Node version: 16.13.1 Moleculer: 0.14.19 Moleculer Web: 0.10.4

alvaroinckot commented 2 years ago

@icebob Do you think that is a good idea to modify the parseQueryString method? I can try do something there

icebob commented 2 years ago

No, the parse method works well, you should change the params validators in mult action as adding convert: true. In this case, validator will convert the string values to number and won't throw validation error.

Like here: https://github.com/moleculerjs/moleculer-web/blob/423741c3da0199966e6c10980b6fe5b8c47a4d4b/examples/math.service.js#L26-L27