ruby-grape / grape-swagger

Add OAPI/swagger v2.0 compliant documentation to your grape API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect type of items in Array

EfremovEvgeniy opened this issue · comments

grape-swagger (0.34.1)

Hi, I have those params at my endpoint

      requires :take_profit, type: Hash do
        requires :enabled, type: Grape::API::Boolean, default: false

        given enabled: -> (value) { value } do
          requires :steps, type: Array, max_length: 8, min_length: 1 do
            requires :order_type, type: String, values: %w[market limit], desc: 'market, limit'
            requires :volume, type: Float, values: 0.0..100.0, coerce_with: ->(c) { c.to_f.round(2) }
            requires :price, type: Hash do
              requires :type, type: String, values: %w[bid ask last], desc: 'bid, ask, last'
              optional :value, type: BigDecimal, desc: 'only if position has no trailing or position trailing is finished'
              optional :percent, type: Float, values: 0.0..300.0, coerce_with: ->(c) { c.to_f.round(2) }, desc: 'only if position has trailing and position trailing is not finished'

              exactly_one_of :value, :percent
            end

            optional :trailing, type: Hash do
              requires :enabled, type: Grape::API::Boolean, default: false
              given enabled: -> (value) { value } do
                requires :percent, type: Float, values: 0.0..100.0, coerce_with: ->(c) { c.to_f.round(2) }
              end
            end
          end
        end
      end

And swagger JSON of this code looks like this

{
      "in": "formData",
      "name": "take_profit[enabled]",
      "type": "boolean",
      "required": true
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][order_type]",
      "description": "market, limit",
      "type": "array",
      "required": true,
      "items": {
        "type": "string",
        "enum": [
          "market",
          "limit"
        ]
      }
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][volume]",
      "type": "array",
      "required": true,
      "items": {
        "type": "number",
        "format": "float"
      }
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][price][type]",
      "description": "bid, ask, last",
      "type": "array",
      "required": true,
      "items": {
        "type": "string"
      }
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][price][value]",
      "description": "only if position has no trailing or position trailing is finished",
      "type": "array",
      "required": false,
      "items": {
        "type": "string"
      }
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][price][percent]",
      "description": "only if position has trailing and position trailing is not finished",
      "type": "array",
      "required": false,
      "items": {
        "type": "string"
      }
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][trailing][enabled]",
      "type": "array",
      "required": true,
      "items": {
        "type": "string"
      }
    },
    {
      "in": "formData",
      "name": "take_profit[steps][][trailing][percent]",
      "type": "array",
      "required": true,
      "items": {
        "type": "string"
      }
    }

Problem in price take_profit[steps][][price][value]
type: BigDecimal, but in JSON it is string(or array of string)
{
"type": "array",
"required": false,
"items": {
"type": "string"
}

The same problem with take_profit[steps][][price][percent]