概要
- GETのクエリパラメータにArray[Integer]を設定してみたがうまく動作しなかった
- そのときのメモ
Grapeはこれ
結論
-
collectionFormat: 'multi'
を追加する
requires :xxx, type: Array[Integer], documentation: { desc: 'メモ', type: 'integer', param_type: 'query', collectionFormat: 'multi' }
この辺にドキュメントがある
困ってたこと
- フロントエンドでGrapeが生成するyamlファイルを元に、ApiClientを生成していたが、リクエストすると
xxx[]=1,2,3
とリクエストしてしまい通らなかった - 通常GETのクエリパラメータでArrayを利用するには、
xxx[]=1&xxx[]=2&xxx[]=3
とする必要がある
こんな感じのTypeScriptが生成されていた
if (xxx) {
localVarQueryParameter[
'xxx[]'
] = xxx.join(COLLECTION_FORMATS.csv)
}
パラメータ修正するとこれになった
if (xxx) {
localVarQueryParameter['xxx[]'] = xxx
}
雑感
とりあえずできた