Class: Rack::JsonSchema::ResponseValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/json_schema/response_validation.rb

Defined Under Namespace

Classes: Error, InvalidResponseContentType, InvalidResponseType, Validator

Instance Method Summary collapse

Constructor Details

#initialize(app, schema: nil) ⇒ ResponseValidation

Behaves as a rack-middleware

Parameters:

  • app (Object)

    Rack application

  • schema (Hash) (defaults to: nil)

    Schema object written in JSON schema format

Raises:

  • (JsonSchema::SchemaError)

8
9
10
11
# File 'lib/rack/json_schema/response_validation.rb', line 8

def initialize(app, schema: nil)
  @app = app
  @schema = Schema.new(schema)
end

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Hash)

    Rack env

Raises:


15
16
17
18
19
# File 'lib/rack/json_schema/response_validation.rb', line 15

def call(env)
  @app.call(env).tap do |response|
    Validator.call(env: env, response: response, schema: @schema)
  end
end