Class: Swaggable::ValidatingRackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/swaggable/validating_rack_app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ValidatingRackApp

Returns a new instance of ValidatingRackApp.



8
9
10
11
# File 'lib/swaggable/validating_rack_app.rb', line 8

def initialize args = {}
  @app = args[:app]
  @definition = args[:definition]
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



3
4
5
# File 'lib/swaggable/validating_rack_app.rb', line 3

def app
  @app
end

Instance Method Details

#call(rack_req) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/swaggable/validating_rack_app.rb', line 13

def call rack_req
  req = RackRequestAdapter.new rack_req

  validator = ApiValidator.new definition: definition, request: req

  errors = validator.errors_for_request
  raise(errors) if errors.any?

  rack_resp = app.call rack_req
  resp = RackResponseAdapter.new rack_resp

  errors = validator.errors_for_response resp
  raise(errors) if errors.any?

  rack_resp
end