Skip to content

Commit 5bda168

Browse files
committed
Simplify collect_variant_types and split dense desc call
StackableValues#[] already returns a flat Array, so the Array(...).flatten(1) wrapping in collect_variant_types was redundant noise. Replace it with a direct .each and update the comment to match reality. Add an explicit failure-mode note: if Grape ever renames the private ivars (@converter, @types, @scope), the method silently returns {} and swagger degrades to the pre-fix broken output rather than crashing. Split the three-operation desc(pop_desc(...), params: ..., **...) one-liner into named locals for readability.
1 parent 2457d42 commit 5bda168

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

lib/grape-swagger/doc_methods.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def setup(options)
105105
.output_path_definitions(target_class.combined_namespace_routes, self, target_class, options)
106106
end
107107

108-
desc(pop_desc(specific_api_doc), params: specific_api_doc.delete(:params) || {}, **specific_api_doc)
108+
specific_desc = pop_desc(specific_api_doc)
109+
specific_params = specific_api_doc.delete(:params) || {}
110+
desc(specific_desc, params: specific_params, **specific_api_doc)
109111

110112
params do
111113
requires :name, type: String, desc: 'Resource name of mounted API'

lib/grape-swagger/request_param_parsers/route.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ def fetch_inherited_params(stackable_values)
5858
# @converter, so we rebuild a name => types map keyed by the fully-qualified
5959
# param name (e.g. "group[inner]") to match route.params keys and avoid
6060
# clobbering same-named params at outer scopes.
61+
#
62+
# NOTE: @converter, @types, and @scope are private Grape ivars. If Grape
63+
# renames them, this method silently returns {} and swagger falls back to
64+
# the pre-fix broken output (coercer inspect string) — not a crash.
6165
def collect_variant_types(stackable_values)
6266
variant_types = {}
6367
return variant_types unless defined?(Grape::Validations::Types::VariantCollectionCoercer) &&
6468
defined?(Grape::Validations::Validators::CoerceValidator) &&
6569
stackable_values.respond_to?(:[])
6670

67-
# `flatten(1)` only collapses the inheritance-stack levels (StackableValues
68-
# stores `[[...level1...], [...level2...]]`); avoids descending into
69-
# validator internals if any ever implements `to_ary`.
70-
Array(stackable_values[:validations]).flatten(1).each do |validator|
71+
# StackableValues#[] concatenates inheritance levels and always returns
72+
# a flat Array of validator instances — no wrapping or flattening needed.
73+
stackable_values[:validations].each do |validator|
7174
next unless validator.is_a?(Grape::Validations::Validators::CoerceValidator)
7275

7376
converter = validator.instance_variable_get(:@converter)

0 commit comments

Comments
 (0)