Class: Jsapi::Meta::Callback::Base

Inherits:
Model::Base show all
Defined in:
lib/jsapi/meta/callback/base.rb

Overview

Specifies a callback. Applies to OpenAPI 3.0 and higher.

Defined Under Namespace

Classes: Operations

Instance Method Summary collapse

Methods inherited from Model::Base

#initialize, #inspect, #merge!, #reference?, #resolve

Methods included from Model::Attributes

#attributes_frozen?, #freeze_attributes, included

Constructor Details

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

Instance Method Details

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

Adds an expression.

Raises an ArgumentError if expression is blank.



70
71
72
73
74
75
76
# File 'lib/jsapi/meta/callback/base.rb', line 70

def add_expression(expression, keywords = {})
  try_modify_attribute!(:expressions) do
    raise ArgumentError, "expression can't be blank" if expression.blank?

    (@expressions ||= {})[expression.to_s] = Operations.new(keywords)
  end
end

#expressionsObject

:attr: expressions



65
# File 'lib/jsapi/meta/callback/base.rb', line 65

attribute :expressions, { String => Operations }, accessors: %i[reader writer]

#to_openapi(version, definitions) ⇒ Object

Returns a hash representing the OpenAPI callback object.



79
80
81
82
83
# File 'lib/jsapi/meta/callback/base.rb', line 79

def to_openapi(version, definitions)
  expressions.transform_values do |operations|
    operations.to_openapi(version, definitions)
  end
end