Class: Odin::Validation::Validator
- Inherits:
-
Object
- Object
- Odin::Validation::Validator
- Defined in:
- lib/odin/validation/validator.rb
Instance Method Summary collapse
-
#validate(doc, schema, options = {}, registry = nil) ⇒ Object
Validate an OdinDocument against an OdinSchema Returns ValidationResult.
Instance Method Details
#validate(doc, schema, options = {}, registry = nil) ⇒ Object
Validate an OdinDocument against an OdinSchema Returns ValidationResult. Pass a registry to resolve @alias.typename refs.
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 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/odin/validation/validator.rb', line 10 def validate(doc, schema, = {}, registry = nil) @errors = [] @doc = doc @schema = schema @registry = registry @strict = .fetch(:strict, false) # V001: Required fields check_required_fields # V002: Type matches check_type_matches # V003: Bounds constraints check_bounds_constraints # V003: Decimal places (#.N) check_decimal_places_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 (document-level) check_circular_references # V013: Unresolved references (document-level) check_unresolved_references # Schema-only checks (V012 type cycles, V013 type refs, V017 well-formedness) # are computed once per schema and reused across documents. @errors.concat(schema_only_errors.map(&:dup)) Errors::ValidationResult.new(@errors) end |