Class: OpenapiFirst::Schema::ValidationError
- Inherits:
-
Data
- Object
- Data
- OpenapiFirst::Schema::ValidationError
- Defined in:
- lib/openapi_first/schema/validation_error.rb
Overview
One of multiple validation errors. Returned by Schema::ValidationResult#errors.
Instance Attribute Summary collapse
-
#data_pointer ⇒ Object
readonly
Returns the value of attribute data_pointer.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#schema_pointer ⇒ Object
readonly
Returns the value of attribute schema_pointer.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#message ⇒ Object
This returns an error message for this specific error.
Instance Attribute Details
#data_pointer ⇒ Object (readonly)
Returns the value of attribute data_pointer
6 7 8 |
# File 'lib/openapi_first/schema/validation_error.rb', line 6 def data_pointer @data_pointer end |
#details ⇒ Object (readonly)
Returns the value of attribute details
6 7 8 |
# File 'lib/openapi_first/schema/validation_error.rb', line 6 def details @details end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema
6 7 8 |
# File 'lib/openapi_first/schema/validation_error.rb', line 6 def schema @schema end |
#schema_pointer ⇒ Object (readonly)
Returns the value of attribute schema_pointer
6 7 8 |
# File 'lib/openapi_first/schema/validation_error.rb', line 6 def schema_pointer @schema_pointer end |
#type ⇒ Object (readonly)
Returns the value of attribute type
6 7 8 |
# File 'lib/openapi_first/schema/validation_error.rb', line 6 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value
6 7 8 |
# File 'lib/openapi_first/schema/validation_error.rb', line 6 def value @value end |
Instance Method Details
#message ⇒ Object
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 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 |