Class: Rack::JsonSchema::RequestValidation

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

Defined Under Namespace

Classes: Error, InvalidContentType, InvalidJson, InvalidParameter, LinkNotFound, Validator

Instance Method Summary collapse

Constructor Details

#initialize(app, ignore_invalid_content_type: false, ignore_missing_path: false, schema: nil) ⇒ RequestValidation

Behaves as a rack-middleware

Parameters:

  • app (Object)

    Rack application

  • ignore_invalid_content_type (false, true) (defaults to: false)

    Ignore requests with non json content-type

  • ignore_missing_path (false, true) (defaults to: false)

    Ignore requests not defined in schema

  • schema (Hash) (defaults to: nil)

    Schema object written in JSON schema format

Raises:

  • (JsonSchema::SchemaError)

10
11
12
13
14
15
# File 'lib/rack/json_schema/request_validation.rb', line 10

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

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Hash)

    Rack env

Raises:


19
20
21
22
23
24
25
26
27
# File 'lib/rack/json_schema/request_validation.rb', line 19

def call(env)
  Validator.call(
    env: env,
    ignore_invalid_content_type: @ignore_invalid_content_type,
    ignore_missing_path: @ignore_missing_path,
    schema: @schema
  )
  @app.call(env)
end