moleculerjs / moleculer-web

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

Allow for array query strings #309

Closed daniel-white closed 1 year ago

daniel-white commented 2 years ago

I have a OAS 3.1 spec that has a query parameter that is an array but uses the non-exploded form such as ?type=main,secondary. The gateway using parse from ljharb/qs & parseQueryString does not seem to account for these additional options and the param ends up in a couple different ways

  1. ?type=main,secondary => "type": "main,secondary" => fails to validate
  2. ?type=main => "type": "main" => fails to validate
  3. ?type=main&type=secondary => "type": ["main", "secondary"] => validates fine

My param config:

{
  type: 'array',
  items: { type: 'string' },
  uniqueItems: true,
  minItems: 1,
  convert: true
}

Should parseQueryString be smarter and respect some other OAS options?

The docs are lacking and just indicate to read up on ljharb/qs

intech commented 2 years ago

?type[]=main&type[]=secondary for more information, read this thread

daniel-white commented 2 years ago

Also: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-examples

daniel-parakey commented 1 year ago

@intech is there a reason we are not allowed to specify this ourselves? For example through passing qsOptions in settings and using it here?

intech commented 1 year ago

@daniel-parakey, welcome for PR for this feature :)

daniel-parakey commented 1 year ago

@intech thoughts? https://github.com/moleculerjs/moleculer-web/pull/326