ApipieBindings::API apipie question

From subscriptions_controller.rb[1]

api :DELETE, "/subscriptions/:id", N_("Unattach a subscription")
api :DELETE, "/systems/:system_id/subscriptions/:id", N_("Unattach a subscription"), :deprecated => true
api :DELETE, "/activation_keys/:activation_key_id/subscriptions/:id", N_("Unattach a subscription")
param :id, String, :desc => N_("Subscription ID"), :required => false
param :system_id, String, :desc => N_("UUID of the system")
param :activation_key_id, String, :desc => N_("activation key ID")
param :subscriptions, Array, :desc => N_("Array of subscriptions to add"), :required => false do
  param :id, String, :desc => N_("Subscription Pool uuid"), :required => true
end

To delete a subscription from a system, how would I use the binding in ruby?

@api = ApipieBinding::API.new()

#api :DELETE, "/subscriptions/:id", N_("Unattach a subscription")
@api.resource(:subscriptions).call(:destroy, {:system_id=>456, :subscriptions => [{:id=>456}]})
# --> Error: missing param 'id' in parameter
@api.resource(:subscriptions).call(:destroy, {:id=>123, :system_id=>456})
# --> Missing arguments for 'subscriptions'

#api :DELETE, "/systems/:system_id/subscriptions/:id", N_("Unattach a subscription"), :deprecated => true
????

#api :DELETE, "/activation_keys/:activation_key_id/subscriptions/:id", N_("Unattach a subscription")
????

Any advice on correcting the apipie document and/or calling the api choices?

[1] https://github.com/Katello/katello/blob/master/app/controllers/katello/api/v2/subscriptions_controller.rb#L106

··· -- @thomasmckay


“The leader must aim high, see big, judge widely, thus setting himself apart form the ordinary people who debate in narrow confines.” ~ Charles De Gaulle

“Leadership is about making others better as a result of your presence and making sure that impact lasts in your absence.” ~ Harvard Business School

Hi Tom,

it seems you've found bug in ApipieBindings. For some reason if some
non-required parameter of type Hash or Array (subscriptions here)
contains nested required parameter it is (probably wrongly) considered
required by the bindings.

On my devel instance I can see this routes (that for unknown reason
doesn't match the docs)

[foretello-devel]# bundle exec rake routes|grep v2|grep
subscription>grep DELETE

api_system_subscription DELETE
/katello/api(/:api_version)/systems/:system_id/subscriptions/:id(.:format)
katello/api/v2/subscriptions#destroy {:api_version=>"v2"}
api_distributor_subscription DELETE
/katello/api(/:api_version)/distributors/:distributor_id/subscriptions/:id(.:format)
katello/api/v2/subscriptions#destroy {:api_version=>"v2"}

So I'd use

@api.resource(:subscriptions).call(:destroy, {:id=>456, :system_id=>456, :subscriptions => [{:id=>456}]})

which worked. If the error is fixed the :subscriptions array should not
be required.

Regards,

Martin

··· On 03/31/2015 11:06 PM, Tom McKay wrote: > From subscriptions_controller.rb[1] > > api :DELETE, "/subscriptions/:id", N_("Unattach a subscription") > api :DELETE, "/systems/:system_id/subscriptions/:id", N_("Unattach a subscription"), :deprecated => true > api :DELETE, "/activation_keys/:activation_key_id/subscriptions/:id", N_("Unattach a subscription") > param :id, String, :desc => N_("Subscription ID"), :required => false > param :system_id, String, :desc => N_("UUID of the system") > param :activation_key_id, String, :desc => N_("activation key ID") > param :subscriptions, Array, :desc => N_("Array of subscriptions to add"), :required => false do > param :id, String, :desc => N_("Subscription Pool uuid"), :required => true > end > > To delete a subscription from a system, how would I use the binding in ruby? > > @api = ApipieBinding::API.new() > > #api :DELETE, "/subscriptions/:id", N_("Unattach a subscription") > @api.resource(:subscriptions).call(:destroy, {:system_id=>456, :subscriptions => [{:id=>456}]}) > # --> Error: missing param 'id' in parameter > @api.resource(:subscriptions).call(:destroy, {:id=>123, :system_id=>456}) > # --> Missing arguments for 'subscriptions' > > #api :DELETE, "/systems/:system_id/subscriptions/:id", N_("Unattach a subscription"), :deprecated => true > ???? > > #api :DELETE, "/activation_keys/:activation_key_id/subscriptions/:id", N_("Unattach a subscription") > ???? > > > Any advice on correcting the apipie document and/or calling the api choices? > > > [1] https://github.com/Katello/katello/blob/master/app/controllers/katello/api/v2/subscriptions_controller.rb#L106