api-regulator 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 712a8be4e5ef4c7528a09aa3f7370f2e5f8024ae15954066ac52663a0c4b5958
4
- data.tar.gz: '09e89ba29c1a970bdedcc1a266ae045b2435dd6f5fb8f1ad66c84cae3007aae1'
3
+ metadata.gz: 2954fc88571b8b3d2086405b0b6973f0202debe1284408531b4a079ba9d86c9c
4
+ data.tar.gz: 0267527b762872e05fe3a84d7145e39958f4616240dc590d3e10f3996650d387
5
5
  SHA512:
6
- metadata.gz: 340219f8c1b4ee3e5bf6c7fe0889ef32f0056f87615a8b4beea9bca235667f2310bc9d0d510a15982ce78d7b79281449c26bb09dc5839f549fdbb2e7d32fb9cf
7
- data.tar.gz: 0d9a361b19a8922cf927a06c66abbf5007e08f790af02c9d30154f9bfa97316e98672fd12d6786374a4660f88b4e8426539b7e1114a2b8d72eced0c9f907e197
6
+ metadata.gz: '06548a9e1bce09a019c2c0e105e3bf34aeabd737dc5f4f802ae3903c0dc0eaae3dfaf841d75d1624948dfc90f465909d6807764a83d6a70c9b9b4922c2c828a9'
7
+ data.tar.gz: d6a151ef312d62ab88bddc1875645fac23945ed37b5afc0fecb8494700e1443849f38172c89c94434c3ecacb413391078bdffd9e2177417bd629cc02559e1c9f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-regulator (0.1.21)
4
+ api-regulator (0.1.23)
5
5
  activemodel (~> 8.0)
6
6
  activesupport (~> 8.0)
7
7
 
@@ -123,10 +123,10 @@ GEM
123
123
  net-smtp (0.5.1)
124
124
  net-protocol
125
125
  nio4r (2.7.4)
126
- nokogiri (1.18.2)
126
+ nokogiri (1.18.3)
127
127
  mini_portile2 (~> 2.8.2)
128
128
  racc (~> 1.4)
129
- nokogiri (1.18.2-arm64-darwin)
129
+ nokogiri (1.18.3-arm64-darwin)
130
130
  racc (~> 1.4)
131
131
  pp (0.6.2)
132
132
  prettyprint
@@ -199,18 +199,18 @@ GEM
199
199
  rspec-support (~> 3.10)
200
200
  rspec-support (3.13.2)
201
201
  securerandom (0.4.1)
202
- stringio (3.1.2)
202
+ stringio (3.1.5)
203
203
  thor (1.3.2)
204
204
  timeout (0.4.3)
205
205
  tzinfo (2.0.6)
206
206
  concurrent-ruby (~> 1.0)
207
- uri (1.0.2)
207
+ uri (1.0.3)
208
208
  useragent (0.16.11)
209
209
  websocket-driver (0.7.7)
210
210
  base64
211
211
  websocket-extensions (>= 0.1.0)
212
212
  websocket-extensions (0.1.5)
213
- zeitwerk (2.7.1)
213
+ zeitwerk (2.7.2)
214
214
 
215
215
  PLATFORMS
216
216
  arm64-darwin-23
@@ -37,12 +37,25 @@ module ApiRegulator
37
37
 
38
38
  body_params = api_definition.params.select(&:body?)
39
39
  permitted_body = body_params.each_with_object({}) do |param, hash|
40
- if param.type == :object
40
+ case param.type
41
+ when :array
42
+ allowed_params = [build_permitted_keys(param.children)]
43
+
44
+ if param.required?
45
+ nested = params.expect(param.name => allowed_params).map { |set| set.to_h.symbolize_keys }
46
+ hash[param.name.to_sym] = nested
47
+ else
48
+ nested = params.permit(param.name => allowed_params).map { |set| set.to_h.symbolize_keys }
49
+ hash.merge!(nested)
50
+ end
51
+ when :object
52
+ allowed_params = build_permitted_keys(param.children)
53
+
41
54
  if param.required?
42
- nested = params.expect(param.name => build_permitted_keys(param.children)).to_h.symbolize_keys
55
+ nested = params.expect(param.name => allowed_params).to_h.symbolize_keys
43
56
  hash[param.name.to_sym] = nested
44
57
  else
45
- nested = params.permit(param.name => build_permitted_keys(param.children)).to_h.symbolize_keys
58
+ nested = params.permit(param.name => allowed_params).to_h.symbolize_keys
46
59
  hash.merge!(nested)
47
60
  end
48
61
  else
@@ -124,6 +124,11 @@ module ApiRegulator
124
124
  return
125
125
  end
126
126
 
127
+ if max = param.options.dig(:length, :maximum)
128
+ errors.add(attribute, "must have a max size of #{max}") if raw_value.length > max
129
+ return
130
+ end
131
+
127
132
  raw_value.each_with_index do |value, index|
128
133
  unless value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
129
134
  errors.add("#{attribute}[#{index}]", "must be a hash")
@@ -355,8 +360,9 @@ module ApiRegulator
355
360
  allowed_arbitrary_keys = params.flat_map(&:allowed_arbitrary_keys).compact
356
361
  extras = []
357
362
  actual_keys.each do |key|
358
- next if allowed_keys.include?(key.gsub(/\[\d+\]/, "[]"))
359
- next if allowed_arbitrary_keys.any? { |aribitrary_key| key.starts_with?(aribitrary_key) }
363
+ deindexed_key = key.gsub(/\[\d+\]/, "[]")
364
+ next if allowed_keys.include?(deindexed_key)
365
+ next if allowed_arbitrary_keys.any? { |aribitrary_key| deindexed_key.starts_with?(aribitrary_key) }
360
366
  extras << key
361
367
  end
362
368
  extras
@@ -1,3 +1,3 @@
1
1
  module ApiRegulator
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.23"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-regulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Massanek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-14 00:00:00.000000000 Z
11
+ date: 2025-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport