Class: Jsapi::Meta::Parameter::Reference

Inherits:
BaseReference show all
Defined in:
lib/jsapi/meta/parameter/reference.rb

Instance Method Summary collapse

Methods inherited from BaseReference

lookup_method_name, #ref, #reference?, #resolve

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

#to_openapi(version, definitions) ⇒ Object

Returns an array of hashes. Each element represents an OpenAPI parameter object if the type of the referred parameter is "object". Otherwise the array contains a single hash representing the OpenAPI reference object.

Raises a ReferenceError if the reference could not be resolved.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jsapi/meta/parameter/reference.rb', line 13

def to_openapi(version, definitions)
  version = OpenAPI::Version.from(version)
  parameter = resolve(definitions)

  if parameter.schema.resolve(definitions).object?
    # Explode referred parameter
    parameter.to_openapi(version, definitions)
  else
    # Return an array containing the reference object
    path = version.major == 2 ? 'parameters' : 'components/parameters'

    [{ '$ref': "#/#{path}/#{ref}" }]
  end
end