Skip to content

Commit

Permalink
Merge pull request #521 from dblock/1-item-arg-groups
Browse files Browse the repository at this point in the history
Fix: support arg groups with just 1 item.
  • Loading branch information
dblock authored Jul 13, 2024
2 parents dfcf059 + 8d3ce6c commit efb0cb8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/slack/web/api/templates/method.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Slack
raise ArgumentError, 'Required arguments :<%= arg_name %> missing' if options[:<%= arg_name %>].nil?
<% end %>
<% data['arg_groups']&.each do |arg_group| %>
<% next if arg_group['args'].size <= 1 %>
<% arg_string = arg_group['args'].map { |arg_name| ":#{arg_name}" }.join(', ') %>
<% if arg_group['mutually_exclusive'] %>
raise ArgumentError, 'Exactly one of <%= arg_string %> is required' unless <%= arg_group['args'].map { |arg_name| "options[:#{arg_name}].nil?" }.join(' ^ ') %>
Expand Down
3 changes: 2 additions & 1 deletion lib/slack/web/api/templates/method_spec.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RSpec.describe Slack::Web::Api::Endpoints::<%= group.gsub(".", "_").camelize %>
let(:client) { Slack::Web::Client.new }
<% names.sort.each_with_index do |(name, data), index| %>
<% next if data['mixin'] %>
<% group_required_params = data['arg_groups']&.map { |grp| grp['args'].first } || [] %>
<% group_required_params = data['arg_groups']&.map { |grp| grp['args'].first if grp['args'].size > 1 } || [] %>
<% required_params = data['args'].select{ |k, v| v['required'] || group_required_params.include?(k) } %>
<% json_params = data['args'].map { |arg_name, arg_v| arg_name if arg_v['format'] == 'json' }.compact %>
<% next if (required_params.none? || custom_spec_exists) && json_params.none? && data['arg_groups'].nil? %>
Expand All @@ -23,6 +23,7 @@ RSpec.describe Slack::Web::Api::Endpoints::<%= group.gsub(".", "_").camelize %>
<% end %>
<% end %>
<% data['arg_groups']&.each do |arg_group| %>
<% next if arg_group['args'].size <= 1 %>
it 'requires one of <%= arg_group['args'].join(', ') %>' do
<% params_except_required = example_params.reject { |name, _| arg_group['args'].include?(name) }.map { |name, val| "#{name}: %q[#{val}]" }.join(', ') %>
<% error_message = arg_group['mutually_exclusive'] ? 'Exactly' : 'At least' %>
Expand Down

0 comments on commit efb0cb8

Please sign in to comment.