Class: LightGptProxy::SchemaValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/light_gpt_proxy/schema_validator.rb

Constant Summary collapse

ValidationError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ SchemaValidator

Returns a new instance of SchemaValidator.



9
10
11
# File 'lib/light_gpt_proxy/schema_validator.rb', line 9

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



7
8
9
# File 'lib/light_gpt_proxy/schema_validator.rb', line 7

def payload
  @payload
end

#schemaObject (readonly)

Returns the value of attribute schema.



7
8
9
# File 'lib/light_gpt_proxy/schema_validator.rb', line 7

def schema
  @schema
end

Instance Method Details

#validate!(payload) ⇒ Object Also known as: []

Raises:



13
14
15
16
17
18
19
# File 'lib/light_gpt_proxy/schema_validator.rb', line 13

def validate!(payload)
  @payload = payload
  errors = validate_schema(schema, payload)
  raise ValidationError, errors.join(', ') if errors.any?

  true
end