Array of entities in request body

オープン
#666 コメント 9 件 リアクション 3 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

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

調査の方向性

Start in lib/grape-swagger/doc_methods/move_params.rb at MoveParams#build_definition, then read the related issue and the request-body examples. Compare the generated specification with Grape's requirement for an object containing the array under a top-level key. Done means the specification represents the intended JSON object without requiring a dummy optional parameter.

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

説明

discuss!

Related issue: https://github.com/ruby-grape/grape-entity/issues/252

As for example above, we want request body to be:

{
  "accounts": [
    {
      "cma": 0,
      "name": "string",
      "environment": "string",
      "sites": 0,
      "username": "string",
      "password": "string"
    }
  ]
}

But actually:

[
    {
      "cma": 0,
      "name": "string",
      "environment": "string",
      "sites": 0,
      "username": "string",
      "password": "string"
    }
]

Grape also wants the array to be in the key of top level JSON object.
( Top level array data cannot be handled by Grape out of the box ( cf. https://github.com/ruby-grape/grape/issues/1730 ). )

So it seems the generated specification is broken.

A workaround is to adding dummy optional parameter.
It forces the request body to be a JSON object.

I've found that making MoveParams#build_definition to always use object_type fixes the issue.
Is this reasonable fix?

主要言語
Ruby
スター
1.1k
フォーク
477
平均マージ
5時間 25分
マージ済み PR(30日)
3

環境構築

はじめの一歩

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

ruby-grape/grape-swagger のほかの issue

ruby-grape/grape-swagger の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

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

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