Class: Lina::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/lina/schema.rb

Class Method Summary collapse

Class Method Details

.api_spec_check(schema, data) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lina/schema.rb', line 56

def self.api_spec_check(schema, data)
  begin
    JSON::Validator.validate!(schema, data)
  rescue JSON::Schema::ValidationError => e
    raise Lina::ApiSpecError, e.message
  end

  validator_message = schema_check(data[:params])
  raise Lina::ApiSpecParamsError, validator_message[0] if validator_message.present?

  validator_message = schema_check(data[:return])
  raise Lina::ApiSpecReturnError, validator_message[0] if validator_message.present?
end

.params_check(schema, data) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/lina/schema.rb', line 34

def self.params_check(schema, data)
  return unless Lina.params_check
  begin
    JSON::Validator.validate!(schema, data, insert_defaults: true)
  rescue JSON::Schema::ValidationError => e
    raise Lina::ParamsCheckError, e.message
  end
end

.return_check(schema, data) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/lina/schema.rb', line 47

def self.return_check(schema, data)
  return unless Lina.return_check
  begin
    JSON::Validator.validate!(schema, data)
  rescue JSON::Schema::ValidationError => e
    raise Lina::ReturnCheckError, e.message
  end
end

.schema_check(schema) ⇒ Object



43
44
45
# File 'lib/lina/schema.rb', line 43

def self.schema_check(schema)
  JSON::Validator.fully_validate_schema(schema)
end