Class: Apiwork::Issue
- Inherits:
-
Object
- Object
- Apiwork::Issue
- Defined in:
- lib/apiwork/issue.rb
Overview
Represents a validation issue found during request parsing.
Issues are returned when request parameters fail validation, coercion, or constraint checks. Access via ‘contract.issues`.
Instance Attribute Summary collapse
-
#code ⇒ Symbol
readonly
The code for this issue.
-
#detail ⇒ String
readonly
The detail for this issue.
-
#meta ⇒ Hash
readonly
The meta for this issue.
- #path ⇒ Object readonly
Instance Method Summary collapse
-
#as_json ⇒ Hash
Converts this issue to a hash for JSON serialization.
-
#initialize(code, detail, meta: {}, path: []) ⇒ Issue
constructor
A new instance of Issue.
-
#pointer ⇒ String
The pointer for this issue.
-
#to_h ⇒ Hash
Converts this issue to a hash.
-
#to_s ⇒ String
Converts this issue to a string.
Constructor Details
#initialize(code, detail, meta: {}, path: []) ⇒ Issue
Returns a new instance of Issue.
35 36 37 38 39 40 |
# File 'lib/apiwork/issue.rb', line 35 def initialize(code, detail, meta: {}, path: []) @code = code @detail = detail @path = path.map { |element| element.is_a?(Integer) ? element : element.to_sym } @meta = end |
Instance Attribute Details
#code ⇒ Symbol (readonly)
The code for this issue.
30 31 32 |
# File 'lib/apiwork/issue.rb', line 30 def code @code end |
#detail ⇒ String (readonly)
The detail for this issue.
30 31 32 33 |
# File 'lib/apiwork/issue.rb', line 30 attr_reader :code, :detail, :meta, :path |
#meta ⇒ Hash (readonly)
The meta for this issue.
30 31 32 33 |
# File 'lib/apiwork/issue.rb', line 30 attr_reader :code, :detail, :meta, :path |
#path ⇒ Object (readonly)
30 31 32 33 |
# File 'lib/apiwork/issue.rb', line 30 attr_reader :code, :detail, :meta, :path |
Instance Method Details
#as_json ⇒ Hash
Converts this issue to a hash for JSON serialization.
68 69 70 |
# File 'lib/apiwork/issue.rb', line 68 def as_json to_h end |
#pointer ⇒ String
The pointer for this issue.
46 47 48 |
# File 'lib/apiwork/issue.rb', line 46 def pointer @pointer ||= JSONPointer.new(*path).to_s end |
#to_h ⇒ Hash
Converts this issue to a hash.
54 55 56 57 58 59 60 61 62 |
# File 'lib/apiwork/issue.rb', line 54 def to_h { code: code, detail: detail, meta: , path: path.map { |segment| segment.is_a?(Integer) ? segment : segment.to_s }, pointer: pointer, } end |
#to_s ⇒ String
Converts this issue to a string.
76 77 78 |
# File 'lib/apiwork/issue.rb', line 76 def to_s "[#{code}]#{path.any? ? " at #{pointer}" : ''} #{detail}" end |