Skip to content

Commit

Permalink
Add show? method to param description (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren authored Jan 6, 2025
1 parent 6ba6cdf commit 4a9fbe1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/apipie_bindings/param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ def initialize(param)
@description = param[:description].gsub(/<\/?[^>]+?>/, "")
@required = !!param[:required]
@validator = param[:validator]
# 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 = param[:show].nil? ? true : param[:show]
end

def required?
@required
end

def show?
@show
end

def to_s
"<Param #{ required? ? '*' : '' }#{@name} (#{@expected_type.to_s.capitalize})>"
end
Expand Down
18 changes: 17 additions & 1 deletion test/unit/param_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
"full_name" => "architecture[name]",
"name" => "name",
"required" => false,
"validator" => "Must be String"
"validator" => "Must be String",
"show" => true
},
{
"allow_nil" => false,
"description" => "",
"expected_type" => "integer",
"full_name" => "architecture[hidden]",
"name" => "hidden",
"required" => false,
"validator" => "Must be Integer",
"show" => false
}

],
Expand Down Expand Up @@ -54,4 +65,9 @@
param.inspect.must_equal "<Param *architecture (Hash)>"
end

it "should have show?" do
param.show?.must_equal true
param.params.first.show?.must_equal true
param.params.last.show?.must_equal false
end
end

0 comments on commit 4a9fbe1

Please sign in to comment.