class Rack::Spec::RequestValidation

Public Class Methods

new(app, schema: nil) click to toggle source

Behaves as a rack-middleware @param app [Object] Rack application @param schema [Hash] Schema object written in JSON schema format @raise [JsonSchema::SchemaError]

# File lib/rack/spec/request_validation.rb, line 8
def initialize(app, schema: nil)
  @app = app
  @schema = Schema.new(schema)
end

Public Instance Methods

call(env) click to toggle source

@raise [Rack::Spec::RequestValidation::Error] Raises if given request is invalid to JSON Schema @param env [Hash] Rack env

# File lib/rack/spec/request_validation.rb, line 15
def call(env)
  Validator.call(env: env, schema: @schema)
  @app.call(env)
end