Class: SpecForge::Forge::Runner::SchemaValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/forge/runner/schema_validator.rb

Overview

Validates JSON structure against a schema definition

Validates that response data matches the expected types and structure defined in shape: or schema: blocks. Supports nested objects, arrays with patterns, and nullable types.

Instance Method Summary collapse

Constructor Details

#initialize(data, schema) ⇒ SchemaValidator

Creates a new schema validator

Parameters:

  • data (Hash, Array)

    The response data to validate

  • schema (Hash)

    The schema definition to validate against



22
23
24
25
26
# File 'lib/spec_forge/forge/runner/schema_validator.rb', line 22

def initialize(data, schema)
  @data = data
  @schema = schema
  @failures = []
end

Instance Method Details

#validate!void

This method returns an undefined value.

Validates the data against the schema definition

Raises:



35
36
37
38
39
# File 'lib/spec_forge/forge/runner/schema_validator.rb', line 35

def validate!
  check_schema(@data, @schema, path: "")

  raise Error::SchemaValidationFailure.new(@failures) if @failures.size > 0
end