Class: Jsapi::Meta::Schema::Reference

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

Instance Method Summary collapse

Methods inherited from BaseReference

lookup_method_name, #ref, #reference?

Methods inherited from Base

#initialize, #inspect, #reference?

Methods included from Attributes::ClassMethods

#attribute, #attribute_names

Constructor Details

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

Instance Method Details

#existenceObject

:attr: existence The level of Existence. The default level of existence is ALLOW_OMITTED.



14
# File 'lib/jsapi/meta/schema/reference.rb', line 14

attribute :existence, Existence, default: Existence::ALLOW_OMITTED

#resolve(definitions) ⇒ Object

:nodoc:



16
17
18
19
20
21
# File 'lib/jsapi/meta/schema/reference.rb', line 16

def resolve(definitions) # :nodoc:
  schema = super
  return schema if existence < Existence::ALLOW_EMPTY

  Delegator.new(schema, [existence, schema.existence].max)
end

#to_json_schemaObject

Returns a hash representing the JSON Schema reference object.



24
25
26
# File 'lib/jsapi/meta/schema/reference.rb', line 24

def to_json_schema
  { '$ref': "#/definitions/#{ref}" }
end

#to_openapi(version) ⇒ Object

Returns a hash representing the OpenAPI reference object.



29
30
31
32
33
34
# File 'lib/jsapi/meta/schema/reference.rb', line 29

def to_openapi(version)
  version = OpenAPI::Version.from(version)
  path = version.major == 2 ? 'definitions' : 'components/schemas'

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