Class: OpenapiContracts::Doc::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/doc/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/openapi_contracts/doc/schema.rb', line 3

def path
  @path
end

#schemaObject (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

#fragmentObject



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


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_hObject



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