loopbackio / loopbackio/loopback-next

@param.array {type: 'object'} throws 400

オープン
#7,777 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug OpenAPI REST
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

## 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、type: 'object' を指定した @param.array を使用する GET リクエストの再現から始め、次に openapi-v3/../parameter.decorator.ts と coerce-parameter.ts を調べて、JSON コンテンツがどのように選択されるかを理解します。配列内の各 JSON オブジェクト文字列がパースされ、リクエストが 400 レスポンスで失敗しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
api
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。