Class: Jsapi::Meta::OpenAPI::Callback::Model

Inherits:
Base
  • Object
show all
Defined in:
lib/jsapi/meta/openapi/callback/model.rb

Overview

Represents a callback object. Applies to OpenAPI 3.x.

Instance Method Summary collapse

Methods inherited from Base

#initialize, #inspect, #reference?, #resolve

Methods included from Attributes::ClassMethods

#attribute, #attribute_names

Constructor Details

This class inherits a constructor from Jsapi::Meta::Base

Instance Method Details

#add_operation(expression, keywords = {}) ⇒ Object

Adds a callback operation.

Raises an ArgumentError if expression is blank.

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/jsapi/meta/openapi/callback/model.rb', line 16

def add_operation(expression, keywords = {})
  raise ArgumentError, "expression can't be blank" if expression.blank?

  (@operations ||= {})[expression.to_s] = Operation.new(nil, keywords)
end

#operation(expression) ⇒ Object

:nodoc:



22
23
24
# File 'lib/jsapi/meta/openapi/callback/model.rb', line 22

def operation(expression) # :nodoc:
  @operations&.[](expression&.to_s)
end

#operationsObject

:attr: operations



11
# File 'lib/jsapi/meta/openapi/callback/model.rb', line 11

attribute :operations, writer: false, default: {}

#to_openapi(version, definitions) ⇒ Object

Returns a hash representing the callback object.



27
28
29
30
31
# File 'lib/jsapi/meta/openapi/callback/model.rb', line 27

def to_openapi(version, definitions)
  operations.transform_values do |operation|
    { operation.method => operation.to_openapi(version, definitions) }
  end
end