Class: Odin::Validation::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/odin/validation/validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(doc, schema, options = {}) ⇒ Object

Validate an OdinDocument against an OdinSchema Returns ValidationResult



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/odin/validation/validator.rb', line 8

def validate(doc, schema, options = {})
  @errors = []
  @doc = doc
  @schema = schema
  @strict = options.fetch(:strict, false)

  # V001: Required fields
  check_required_fields

  # V002: Type matches
  check_type_matches

  # V003: Bounds constraints
  check_bounds_constraints

  # V004: Pattern constraints
  check_pattern_constraints

  # V004 (format): Format constraints
  check_format_constraints

  # V005: Enum constraints
  check_enum_constraints

  # V006: Array length constraints
  check_array_lengths

  # V007: Uniqueness constraints
  check_uniqueness

  # V008: Invariant validation
  check_invariants

  # V009: Cardinality constraints
  check_cardinality

  # V010: Conditional requirements
  check_conditionals

  # V011: Unknown fields (strict mode)
  check_unknown_fields if @strict

  # V012: Circular references
  check_circular_references

  # V013: Unresolved references
  check_unresolved_references

  Errors::ValidationResult.new(@errors)
end