moleculer-web icon indicating copy to clipboard operation
moleculer-web copied to clipboard

Allow for array query strings

Open daniel-white opened this issue 2 years ago • 2 comments

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

daniel-white avatar May 04 '22 00:05 daniel-white

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

intech avatar May 04 '22 21:05 intech

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

daniel-white avatar May 04 '22 22:05 daniel-white

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

daniel-parakey avatar Jun 26 '23 14:06 daniel-parakey

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

intech avatar Jun 26 '23 14:06 intech

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

daniel-parakey avatar Jun 27 '23 07:06 daniel-parakey