Class: OpenapiFirst::Schema::ValidationError

Inherits:
Data
  • Object
show all
Defined in:
lib/openapi_first/schema/validation_error.rb

Overview

One of multiple validation errors. Returned by Schema::ValidationResult#errors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#data_pointerObject (readonly)

Returns the value of attribute data_pointer

Returns:

  • the current value of data_pointer



6
7
8
# File 'lib/openapi_first/schema/validation_error.rb', line 6

def data_pointer
  @data_pointer
end

#detailsObject (readonly)

Returns the value of attribute details

Returns:

  • the current value of details



6
7
8
# File 'lib/openapi_first/schema/validation_error.rb', line 6

def details
  @details
end

#schemaObject (readonly)

Returns the value of attribute schema

Returns:

  • the current value of schema



6
7
8
# File 'lib/openapi_first/schema/validation_error.rb', line 6

def schema
  @schema
end

#schema_pointerObject (readonly)

Returns the value of attribute schema_pointer

Returns:

  • the current value of schema_pointer



6
7
8
# File 'lib/openapi_first/schema/validation_error.rb', line 6

def schema_pointer
  @schema_pointer
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • the current value of type



6
7
8
# File 'lib/openapi_first/schema/validation_error.rb', line 6

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • the current value of value



6
7
8
# File 'lib/openapi_first/schema/validation_error.rb', line 6

def value
  @value
end

Instance Method Details

#messageObject

This returns an error message for this specific error. This it copied from json_schemer here to be easier to customize when passing custom data_pointers.



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
# File 'lib/openapi_first/schema/validation_error.rb', line 9

def message
  location = data_pointer.empty? ? 'root' : "`#{data_pointer}`"

  case type
  when 'required'
    keys = details.fetch('missing_keys', []).join(', ')
    "object at #{location} is missing required properties: #{keys}"
  when 'dependentRequired'
    keys = details.fetch('missing_keys').join(', ')
    "object at #{location} is missing required properties: #{keys}"
  when 'string', 'boolean', 'number'
    "value at #{location} is not a #{type}"
  when 'array', 'object', 'integer'
    "value at #{location} is not an #{type}"
  when 'null'
    "value at #{location} is not #{type}"
  when 'pattern'
    "string at #{location} does not match pattern: #{schema.fetch('pattern')}"
  when 'format'
    "value at #{location} does not match format: #{schema.fetch('format')}"
  when 'const'
    "value at #{location} is not: #{schema.fetch('const').inspect}"
  when 'enum'
    "value at #{location} is not one of: #{schema.fetch('enum')}"
  when 'minimum'
    "number at #{location} is less than: #{schema['minimum']}"
  when 'maximum'
    "number at #{location} is greater than: #{schema['maximum']}"
  when 'readOnly'
    "value at #{location} is `readOnly`"
  else
    "value at #{location} is invalid (#{type.inspect})"
  end
end