Skip to content

Commit f366c8d

Browse files
authored
Fix missing nested param error for nested array params (#1085)
* Remove unreachable code `Lucky::Params#nested_arrays?` returns a hash, which is truthy. * Simplify calls `Lucky::Params#nested_file?` returns a hash always, although its signature says it returns a nilable hash. * Fix error with nested arrays Even if nested params is not empty, Lucky would still raise `Lucky::MissingNestedParamError` if any array attributes are empty. You had to fill in the array attribute to avoid the error: ``` response = client.exec(Features::Create, feature: { choices: Array(String).new, # Without this, you get "Missing param key: 'feature' (Lucky::MissingNestedParamError)..." maximum: 99, minimum: 3, name: "Number of Kitchens", type: :integer }) ```
1 parent c1827c6 commit f366c8d

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/avram/add_column_attributes.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Avram::AddColumnAttributes
2424
return {} of String => Array(String) | String if @@permitted_param_keys.empty?
2525

2626
single_values = @params.nested(self.class.param_key).reject {|k,v| k.ends_with?("[]")}
27-
array_values = @params.nested_arrays?(self.class.param_key) || {} of String => Array(String)
27+
array_values = @params.nested_arrays?(self.class.param_key)
2828
new_params = single_values.merge(array_values)
2929
new_params.select(@@permitted_param_keys)
3030
end

src/avram/attribute.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Avram::Attribute(T)
8787
end
8888

8989
private def extract(params, type : Array(T).class) forall T
90-
nested_params = params.nested_arrays(param_key)
90+
nested_params = params.nested_arrays?(param_key)
9191
param_val = nested_params[name.to_s]?
9292
@param = param_val.try(&.first?)
9393
return if param_val.nil?
@@ -102,7 +102,7 @@ class Avram::Attribute(T)
102102

103103
private def extract(params, type : Avram::Uploadable.class)
104104
file = params.nested_file?(param_key)
105-
@param = param_val = file.try(&.[]?(name.to_s))
105+
@param = param_val = file[name.to_s]?
106106
return if param_val.nil?
107107

108108
parse_result = Avram::Uploadable.adapter.parse(param_val)

0 commit comments

Comments
 (0)