Class: OpenapiContracts::Doc::Schema
- Inherits:
-
Object
- Object
- OpenapiContracts::Doc::Schema
- Defined in:
- lib/openapi_contracts/doc/schema.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #at_path(path) ⇒ Object
- #fragment ⇒ Object
-
#initialize(schema, path = nil) ⇒ Schema
constructor
A new instance of Schema.
- #navigate(*sub_path) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(schema, path = nil) ⇒ Schema
Returns a new instance of Schema.
5 6 7 8 |
# File 'lib/openapi_contracts/doc/schema.rb', line 5 def initialize(schema, path = nil) @schema = schema @path = path.freeze end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/openapi_contracts/doc/schema.rb', line 3 def path @path end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
3 4 5 |
# File 'lib/openapi_contracts/doc/schema.rb', line 3 def schema @schema end |
Instance Method Details
#at_path(path) ⇒ Object
16 17 18 |
# File 'lib/openapi_contracts/doc/schema.rb', line 16 def at_path(path) self.class.new(schema, path) end |
#fragment ⇒ Object
10 11 12 |
# File 'lib/openapi_contracts/doc/schema.rb', line 10 def fragment path.map { |p| p.gsub('/', '~1') }.join('/').then { |s| "#/#{s}" } end |
#navigate(*sub_path) ⇒ Object
26 27 28 |
# File 'lib/openapi_contracts/doc/schema.rb', line 26 def navigate(*sub_path) self.class.new(schema, (path + Array.wrap(sub_path))) end |
#to_h ⇒ Object
20 21 22 23 24 |
# File 'lib/openapi_contracts/doc/schema.rb', line 20 def to_h return @schema if path.nil? || path.empty? @schema.dig(*path) end |