Class: RequestHandler::BodyParser

Inherits:
SchemaParser show all
Defined in:
lib/request_handler/body_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(request:, schema:, schema_options: {}, included_schemas: {}) ⇒ BodyParser

Returns a new instance of BodyParser.



6
7
8
9
10
11
# File 'lib/request_handler/body_parser.rb', line 6

def initialize(request:, schema:, schema_options: {}, included_schemas: {})
  raise MissingArgumentError, :"request.body" => 'is missing' if request.body.nil?
  super(schema: schema, schema_options: schema_options)
  @request = request
  @included_schemas = included_schemas
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
# File 'lib/request_handler/body_parser.rb', line 13

def run
  body, *included = flattened_request_body
  unless included_schemas?
    raise SchemaValidationError, included: 'must be empty' unless included.empty?
    return validate_schema(body)
  end

  validate_schemas(body, included)
end