Skip to content

Commit

Permalink
Fixes #38077 - Don't build hidden params as options
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jan 6, 2025
1 parent dacb09a commit cd062b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/hammer_cli/apipie/option_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def option(*args)
def options_for_params(params, filter, resource_name_map, opts = {})
options = []
params.each do |p|
next unless p.show?
exists = opts[:command].find_option(option_switch(p, resource_name_map))
next if filter.include?(p.name) || filter.include?(p.name.to_sym) || exists

Expand Down Expand Up @@ -85,6 +86,7 @@ def option_opts(param, resource_name_map)
opts[:attribute_name] = HammerCLI.option_accessor_name(param.name)
opts[:referenced_resource] = resource_name(param)
opts[:aliased_resource] = aliased_name(resource_name(param), resource_name_map)
opts[:show] = param.show?

return opts
end
Expand Down
6 changes: 6 additions & 0 deletions lib/hammer_cli/options/option_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def initialize(switches, type, description, options = {})
@context_target = options[:context_target]
@deprecated_switches = options[:deprecated]
@family = options[:family]
# We expect a value from API param docs, but in case it's not there, we want to show it in help by default
@show = options.fetch(:show, true)
super
end

Expand Down Expand Up @@ -153,6 +155,10 @@ def child?
@family.children.include?(self)
end

def show?
@show
end

private

def format_deprecation_msg(option_desc, deprecation_msg)
Expand Down
10 changes: 10 additions & 0 deletions test/unit/apipie/option_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,14 @@
end
end

context "hidden parameters" do
let(:action) { resource.action(:create) }

it "should skip options for params with show? false" do
option_switches = options.map(&:long_switch)
refute_includes(option_switches, "--hidden")
refute_includes(option_switches, "--documented-scope")
end
end

end
20 changes: 20 additions & 0 deletions test/unit/fixtures/apipie/documented.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@
"examples": [],
"errors": [],
"params": [
{
"allow_null": false,
"name": "documented_scope",
"full_name": "documented_scope",
"validator": "Must be String",
"description": "",
"expected_type": "string",
"required": false,
"show": false
},
{
"allow_null": false,
"name": "documented",
Expand Down Expand Up @@ -110,6 +120,16 @@
"expected_type": "array",
"description": "",
"required": true
},
{
"name": "hidden",
"allow_null": false,
"full_name": "documented[hidden]",
"validator": "Must be number",
"expected_type": "number",
"description": "",
"required": false,
"show": false
}
]
}
Expand Down

0 comments on commit cd062b0

Please sign in to comment.