Skip to content

Commit 4894509

Browse files
committed
Clarify validator-shape comments
1 parent 5ed3bc7 commit 4894509

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/grape-swagger/request_param_parsers/route.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def fetch_inherited_params(stackable_values)
5050

5151
# Grape 3.2+ serializes `type: [A, B]` via VariantCollectionCoercer#to_s, losing the type list.
5252
# Recover it from the matching CoerceValidator entry in stackable_values[:validations].
53+
# Grape 3.2+ stores validator metadata as Hash entries; older supported versions use
54+
# CoerceValidator object instances and require private-ivar reads below.
5355
# If the internal structure changes in a future Grape version this silently returns {}.
5456
def collect_variant_types(stackable_values)
5557
variant_types = {}

spec/swagger_v2/param_multi_type_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def app
112112
end
113113

114114
# Canary tests for Grape internals used by collect_variant_types.
115-
# Fails after a Grape upgrade? Update collect_variant_types private-ivar reads.
115+
# Fails after a Grape upgrade? Update collect_variant_types to match the new
116+
# validator shape. Grape 3.2+: Hash entries (key lookups). Older supported
117+
# versions: object instances (private-ivar reads).
116118
describe 'Grape internal contract for collect_variant_types' do
117119
before { skip unless defined?(Grape::Validations::Types::VariantCollectionCoercer) }
118120

@@ -147,7 +149,7 @@ def app
147149
expect(coerce_validator).not_to be_nil
148150
end
149151

150-
it 'recovers types from the Hash-shaped validator path' do
152+
it 'processes a Hash-shaped validator entry (unit test of entry-parsing logic)' do
151153
scope = Struct.new(:name) do
152154
def full_name(attr)
153155
attr.to_s
@@ -198,6 +200,7 @@ def app
198200
end
199201

200202
it 'uses the last-declared type' do
203+
# Relies on validators being iterated in declaration order; last write wins.
201204
types = subject.to_h { |p| [p['name'], p['type']] }
202205
expect(types['n']).to eq('string')
203206
end

0 commit comments

Comments
 (0)