Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 459 forks source link

Can't get Hash inside def_param_group to work #719

Open nexxus-vi opened 3 years ago

nexxus-vi commented 3 years ago

Hi, i'm using 'apipie-rails 0.5.18' in my project. I need to have a json response that looks like this:

  "id": "my1d",
  "device_id": "123",
  "measures": [
    {
      "2021-07-02T15:24:36+02:00": {
        "alarms": [
          "bedroom",
          "garage"
        ],
        "sensor_data": [
          {
            "value": 100,
            "sensor_name": "water"
          },
          {
            "value": 0,
            "sensor": "light"
          }
        ]
      }
    }
  ],
  "created_at": "2021-07-02T14:24:34.824+02:00",
  "updated_at": "2021-07-02T14:34:04.429+02:00"
}

specifically inside measures array, I need an hash with a Date (or String) as key, and a complex object as value.

so in my controller i'm doing:

def_param_group :measure_data do
    property :owner, String
    property :alarms, Array do
      param_group :alarm, AlarmsController
    end
  end

  def_param_group :measures do
    property :measures, :array_of => Hash do
      property :date, Date, "Date of creation"
      param_group :measure_data, JsonMeasuresController
    end
  end

  def_param_group :json_measure do
    property :id, String, required: false
    param :device_id, String, required: true
    property :measures, Array, desc: 'List of measures' do
      param_group :measures, JsonMeasuresController
    end

    property :created_at, Date
    property :updated_at, Date
  end

But when i got the swagger json, the Hash is broken:

{
  "id": "string",
  "device_id": "string",
  "measures": [
    "string"
  ],
  "created_at": "string",
  "updated_at": "string"
}

I can't get the Hash to work in any way. It always returns an array with only "string".

hkjasf687261gh commented 2 years ago

I'm having the same issue,

An array of hashes is always returning array of string instead.

hkjasf687261gh commented 2 years ago

@xxz3 this merge request fixes my issue, been around for a while with no action. You might need to fork your own.

https://github.com/Apipie/apipie-rails/pull/689

mathieujobin commented 2 years ago

@hkjasf687261gh Sorry If I am 8 months late since your last comment... are you saying we could merge #689 and close this one ?

mathieujobin commented 2 years ago

Sorry for the long wait, v0.8.0 will get this fixed