Module: Gitlab::GrapeOpenapi::GrapeCompat

Defined in:
lib/gitlab/grape_openapi/grape_compat.rb

Overview

Isolates the Grape internals this gem reads so version differences live in one place.

Grape < 3.2 stores each declared validation as a Hash; Grape >= 3.2 stores a frozen validator instance instead (ruby-grape/grape#2657). Both shapes are normalized to the Hash the converters expect.

Class Method Summary collapse

Class Method Details

.validations_for(route, attribute) ⇒ Object

Declared validations for a single attribute, newest scope only.

Reads new_values rather than [] or route[:saved_validations] on purpose: those also include validations inherited from parent scopes, which would change the generated output.



18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/grape_openapi/grape_compat.rb', line 18

def validations_for(route, attribute)
  validations = route.app.inheritable_setting.namespace_stackable.new_values[:validations]
  return unless validations

  validations.filter_map do |validation|
    normalized = normalize(validation)
    normalized if normalized && normalized[:attributes].include?(attribute)
  end
end