Class: DryOpenApi::PathItem
- Inherits:
-
Object
- Object
- DryOpenApi::PathItem
- 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
-
#description ⇒ Object
Returns the value of attribute description.
-
#operations ⇒ Object
Returns the value of attribute operations.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#ref ⇒ Object
Returns the value of attribute ref.
-
#servers ⇒ Object
Returns the value of attribute servers.
-
#summary ⇒ Object
Returns the value of attribute summary.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ref: nil, summary: nil, description: nil, servers: nil, parameters: nil, **operations) ⇒ PathItem
constructor
A new instance of PathItem.
- #serializable_hash ⇒ Object
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
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/dry_open_api/path_item.rb', line 6 def description @description end |
#operations ⇒ Object
Returns the value of attribute operations.
6 7 8 |
# File 'lib/dry_open_api/path_item.rb', line 6 def operations @operations end |
#parameters ⇒ Object
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/dry_open_api/path_item.rb', line 6 def parameters @parameters end |
#ref ⇒ Object
Returns the value of attribute ref.
6 7 8 |
# File 'lib/dry_open_api/path_item.rb', line 6 def ref @ref end |
#servers ⇒ Object
Returns the value of attribute servers.
6 7 8 |
# File 'lib/dry_open_api/path_item.rb', line 6 def servers @servers end |
#summary ⇒ Object
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_hash ⇒ Object
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 |