class RspecContracts::Contract

Public Class Methods

new(schema) click to toggle source
# File lib/rspec_contracts/contract.rb, line 5
def initialize(schema)
  @schema = schema.with_indifferent_access
  @root = OpenAPIParser.parse(schema)
end

Public Instance Methods

[](key) click to toggle source
# File lib/rspec_contracts/contract.rb, line 10
def [](key)
  return RspecContracts::Operation.new(nil, self) unless operations.key?(key)

  operations[key]
end
method_missing(m, *args, &block) click to toggle source
# File lib/rspec_contracts/contract.rb, line 36
def method_missing(m, *args, &block)
  @root.send(m, *args, &block)
end
operations() click to toggle source
# File lib/rspec_contracts/contract.rb, line 22
def operations
  @operations ||= paths.map do |p|
    p._openapi_all_child_objects.values.map do |op|
      next unless op.respond_to?(:operation_id)

      [op.operation_id, RspecContracts::Operation.new(op, self)]
    end.compact.to_h
  end.inject(:merge).with_indifferent_access
end
paths() click to toggle source
# File lib/rspec_contracts/contract.rb, line 32
def paths
  @paths ||= @root.paths._openapi_all_child_objects.values
end
version() click to toggle source
# File lib/rspec_contracts/contract.rb, line 16
def version
  @schema[:info][:version]
rescue NoMethodError => _e
  raise RspecContracts::Error.new("Version not found in schema")
end