Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38077 - Don't build hidden params as options #390

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading