Class: DryOpenApi::PathItem

Inherits:
Object
  • Object
show all
Includes:
EquatableAsContent
Defined in:
lib/dry_open_api/path_item.rb

Overview

Constant Summary collapse

OPERATION_NAMES =
%i[get put post delete options head patch trace].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EquatableAsContent

#==

Constructor Details

#initialize(ref: nil, summary: nil, description: nil, servers: nil, parameters: nil, **operations) ⇒ PathItem

Returns a new instance of PathItem.



10
11
12
13
14
15
16
17
# File 'lib/dry_open_api/path_item.rb', line 10

def initialize(ref: nil, summary: nil, description: nil, servers: nil, parameters: nil, **operations)
  self.ref = ref
  self.summary = summary
  self.description = description
  self.servers = servers
  self.parameters = parameters
  self.operations = operations.map { |k, v| [k.to_s.underscore, v] }.to_h.with_indifferent_access
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/dry_open_api/path_item.rb', line 6

def description
  @description
end

#operationsObject

Returns the value of attribute operations.



6
7
8
# File 'lib/dry_open_api/path_item.rb', line 6

def operations
  @operations
end

#parametersObject

Returns the value of attribute parameters.



6
7
8
# File 'lib/dry_open_api/path_item.rb', line 6

def parameters
  @parameters
end

#refObject

Returns the value of attribute ref.



6
7
8
# File 'lib/dry_open_api/path_item.rb', line 6

def ref
  @ref
end

#serversObject

Returns the value of attribute servers.



6
7
8
# File 'lib/dry_open_api/path_item.rb', line 6

def servers
  @servers
end

#summaryObject

Returns the value of attribute summary.



6
7
8
# File 'lib/dry_open_api/path_item.rb', line 6

def summary
  @summary
end

Class Method Details

.load(hash) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dry_open_api/path_item.rb', line 29

def self.load(hash)
  operations = hash.select { |key| key.to_sym.in?(OPERATION_NAMES) }

  new(
    ref: hash['$ref']&.to_s,
    summary: hash['summary']&.to_s,
    description: hash['description']&.to_s,
    servers: hash['servers']&.map { |server_hash| Server.load(server_hash) },
    parameters: hash['parameters']&.map { |h| Reference.load(h) || Parameter.load(h) },
    **operations.map { |k, v| [k.to_sym, Operation.load(v)] }.to_h
  )
end

Instance Method Details

#serializable_hashObject



19
20
21
22
23
24
25
26
27
# File 'lib/dry_open_api/path_item.rb', line 19

def serializable_hash
  {
    'ref' => ref&.to_s,
    'summary' => summary&.to_s,
    'description' => description&.to_s,
    'servers' => servers&.map(&:serializable_hash),
    'parameters' => parameters&.map(&:serializable_hash)
  }.merge(operations.map { |k, v| [k.to_s.underscore, v.serializable_hash] }.to_h).compact
end