Class: Cangaroo::ValidateJsonSchema

Inherits:
Object
  • Object
show all
Includes:
Interactor
Defined in:
app/interactors/cangaroo/validate_json_schema.rb

Constant Summary collapse

SCHEMA =
{
  'id': 'Cangaroo Object',
  'type': 'object',
  'minProperties': 1,
  'additionalProperties': false,
  'patternProperties': {
    '^[a-z\-_]*$': {
      'type': 'array',
      'items': {
        'type': 'object',
        'required': ['id']
      }
    }
  }
}.freeze

Instance Method Summary collapse

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
# File 'app/interactors/cangaroo/validate_json_schema.rb', line 23

def call
  validation_response = JSON::Validator.fully_validate(SCHEMA, context.json_body.to_json)

  if validation_response.empty?
    return true
  end

  context.fail!(message: validation_response.join(', '), error_code: 500)
end