1
0

GrapeでGETのクエリパラメータにArray[Integer]のTypeを使いたいときのメモ

Last updated at Posted at 2024-07-08

概要

  • 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
}

雑感

とりあえずできた

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0