Class: OpenapiContracts::Doc

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

Defined Under Namespace

Modules: WithParameters Classes: Header, Operation, Parameter, Path, Pointer, Request, Response, Schema

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Doc

Returns a new instance of Doc.



19
20
21
22
23
24
25
26
# File 'lib/openapi_contracts/doc.rb', line 19

def initialize(raw)
  @schema = Schema.new(raw)
  @paths = @schema['paths'].to_h do |path, _|
    [path, Path.new(path, @schema.at_pointer(Doc::Pointer['paths', path]))]
  end
  @dynamic_paths = paths.select(&:dynamic?)
  @coverage = Coverage.new(self)
end

Instance Attribute Details

#coverageObject (readonly)

Returns the value of attribute coverage.



17
18
19
# File 'lib/openapi_contracts/doc.rb', line 17

def coverage
  @coverage
end

#schemaObject (readonly)

Returns the value of attribute schema.



17
18
19
# File 'lib/openapi_contracts/doc.rb', line 17

def schema
  @schema
end

Class Method Details

.parse(dir, filename = 'openapi.yaml') ⇒ Object



13
14
15
# File 'lib/openapi_contracts/doc.rb', line 13

def self.parse(dir, filename = 'openapi.yaml')
  new Parser.call(dir, filename)
end

Instance Method Details

#operation_for(path, method) ⇒ Object



33
34
35
# File 'lib/openapi_contracts/doc.rb', line 33

def operation_for(path, method)
  OperationRouter.new(self).route(path, method.downcase)
end

#operations(&block) ⇒ Object

Returns an Enumerator over all Operations



38
39
40
41
42
43
44
# File 'lib/openapi_contracts/doc.rb', line 38

def operations(&block)
  return enum_for(:operations) unless block_given?

  paths.each do |path|
    path.operations.each(&block)
  end
end

#pathsObject

Returns an Enumerator over all paths



29
30
31
# File 'lib/openapi_contracts/doc.rb', line 29

def paths
  @paths.each_value
end

#responses(&block) ⇒ Object

Returns an Enumerator over all Responses



47
48
49
50
51
52
53
# File 'lib/openapi_contracts/doc.rb', line 47

def responses(&block)
  return enum_for(:responses) unless block_given?

  operations.each do |operation|
    operation.responses.each(&block)
  end
end

#with_path(path) ⇒ Object



55
56
57
# File 'lib/openapi_contracts/doc.rb', line 55

def with_path(path)
  @paths[path]
end