Class: Swaggable::ValidatingRackApp
- Inherits:
-
Object
- Object
- Swaggable::ValidatingRackApp
- Defined in:
- lib/swaggable/validating_rack_app.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
- #call(rack_req) ⇒ Object
-
#initialize(args = {}) ⇒ ValidatingRackApp
constructor
A new instance of ValidatingRackApp.
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
#app ⇒ Object
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 |