Apipie / apipie-rails

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

Plural params name doesn't work #564

Open arefinbigfuture opened 6 years ago

arefinbigfuture commented 6 years ago

Here is my code. if I write plural "param :asset_allocations, Array do" it doesn't work but if i write singular "param :asset_allocation, Array do" it works.

using Rails 5.0.2 ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]

What I am missing?

module Api::V1 class FundsController < Api::V1::BaseController before_action :authenticate_user!, except: []

def_param_group :asset_allocations do
  param :asset_allocation, Array do
    param :id, Integer, "POST doesn't require any value."
    param :fund_id, Integer, "fund_id from Fund"
    param :asset_class_id, Integer, "asset_class_id from AssetClass"
    param :rate, Float
  end
end

def_param_group :fund do
  param :fund, Hash do
    param :name, String, "Name of the fund"
    param_group :asset_allocations
  end
end

api :POST, '/v1/funds', 'Creates a fund.'
param_group :fund
def create
  fund = Fund.new(fund_params)
  auth_fund = authorize_with_permissions(fund)

  if fund.save
    render json: auth_fund.record,
      serializer: Api::V1::FundSerializer,
      status: 201
  else
    render json: fund.errors,
      status: 406
  end
end

private
  def fund_params
    fund_ps = params.require(:fund).permit(:name, 
      asset_allocations: [:id, :fund_id, :asset_class_id, :rate, :_destory])

    fund_ps[:asset_allocations_attributes] = fund_ps.delete :asset_allocations
    fund_ps.permit!
  end

end end

iNecas commented 6 years ago

Hi, AFAIK we don't do any logic around singular/plural in the Apipie. Could you try reproducing this in https://github.com/Apipie/apipie-rails/tree/master/spec/dummy?