loopbackio / loopbackio/loopback-next
@param.array {type: 'object'} throws 400
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 5.1k
- Fork
- 1.1k
- Merge medio
- 2g 21h
- PR unite (30g)
- 27
Descrizione
## Steps to reproduce
In explorer, make a GET request to a controller that has an array of type: 'object': `@param.array('objectArray', 'query', {type: 'object'})`
## Current Behavior
When making a GET request to a controller with an array of objects parameter `@param.array('objectArray', 'query', {type: 'object'})`, it will throw a 400 `[{path: "/0", code: "type", message: "must be object", info: {type: "object"}}]` because it doesn't parse the JSON string.
Example:
`/getWithObjectArray?objectArray=%7B%22name%22%3A%22hello%22%7D`
essentially parses to:
`['{"name":"hello"}']`
## Expected Behavior
The request should parse the json string in each array item so the request does not fail.
## Link to reproduction sandbox
Added a test to show it broken: https://github.com/kyle-apex/loopback-next/commit/3d9d8e602f8a747e63ced1cf443f92a59998f35f
Added some code to show it "fixed": https://github.com/kyle-apex/loopback-next/commit/0a69964708fe2f135acd47900d86636dc199a515
My "fix" may be too broad. In openapi-v3/../parameter.decorator.ts, `@param.query.param` forces `content: { 'application/json': { schema, }, }` so coerce-parameter.ts knows to parse the JSON. `@param.array` doesn't have a similar capability, so it's tough for coerce-parameter.ts to know if it should parse the object represented as a string as JSON or not.
Any ideas for best approach?
## Additional information
darwin x64 12.18.1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo una richiesta GET che usa @param.array con type: 'object', quindi esamina openapi-v3/../parameter.decorator.ts e coerce-parameter.ts per capire come viene selezionato il contenuto JSON. È completato quando ogni stringa di oggetto JSON nell'array viene analizzata, in modo che la richiesta non fallisca più con una risposta 400.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- api
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100