Class: Jsapi::Meta::Model::Reference
- Defined in:
- lib/jsapi/meta/model/reference.rb
Overview
The base reference class.
Direct Known Subclasses
Callback::Reference, Example::Reference, Header::Reference, Link::Reference, Parameter::Reference, RequestBody::Reference, Response::Reference, Schema::Reference
Constant Summary
Constants included from Attributes
Attributes::DEFAULT_ARRAY, Attributes::DEFAULT_HASH
Class Method Summary collapse
-
.component_type ⇒ Object
Derrives the component type from the inner most module name.
-
.openapi_component_type ⇒ Object
Derrives the OpenAPI component type from the inner most module name.
Instance Method Summary collapse
-
#description ⇒ Object
:attr: description The description to be displayed instead of the description of the referred object.
-
#ref ⇒ Object
:attr: ref The name of the referred object.
-
#reference? ⇒ Boolean
Returns true.
-
#resolve(definitions) ⇒ Object
Resolves
refby looking up the object with that name indefinitions. -
#summary ⇒ Object
:attr: summary The summary to be displayed instead of the summary of the referred object.
-
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI reference object.
Methods inherited from Base
#initialize, #inspect, #merge!
Methods included from Attributes
Constructor Details
This class inherits a constructor from Jsapi::Meta::Model::Base
Class Method Details
.component_type ⇒ Object
Derrives the component type from the inner most module name.
9 10 11 |
# File 'lib/jsapi/meta/model/reference.rb', line 9 def self.component_type @component_type ||= name.split('::')[-2].underscore end |
.openapi_component_type ⇒ Object
Derrives the OpenAPI component type from the inner most module name.
14 15 16 |
# File 'lib/jsapi/meta/model/reference.rb', line 14 def self.openapi_component_type @openapi_component_type ||= name.split('::')[-2].pluralize.camelize(:lower) end |
Instance Method Details
#description ⇒ Object
:attr: description The description to be displayed instead of the description of the referred object. Applies to OpenAPI 3.1 and higher.
22 |
# File 'lib/jsapi/meta/model/reference.rb', line 22 attribute :description, String |
#ref ⇒ Object
:attr: ref The name of the referred object.
27 |
# File 'lib/jsapi/meta/model/reference.rb', line 27 attribute :ref, String |
#reference? ⇒ Boolean
Returns true.
36 37 38 |
# File 'lib/jsapi/meta/model/reference.rb', line 36 def reference? true end |
#resolve(definitions) ⇒ Object
Resolves ref by looking up the object with that name in definitions.
Raises a ReferenceError if ref could not be resolved.
43 44 45 46 47 48 |
# File 'lib/jsapi/meta/model/reference.rb', line 43 def resolve(definitions) object = definitions.send("find_#{self.class.component_type}", ref) raise ReferenceError, ref if object.nil? object.resolve(definitions) end |
#summary ⇒ Object
:attr: summary The summary to be displayed instead of the summary of the referred object. Applies to OpenAPI 3.1 and higher.
33 |
# File 'lib/jsapi/meta/model/reference.rb', line 33 attribute :summary, String |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI reference object.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jsapi/meta/model/reference.rb', line 51 def to_openapi(version, *) version = OpenAPI::Version.from(version) { '$ref': "#/#{openapi_components_path(version)}/#{ref}" }.tap do |result| if version >= OpenAPI::V3_1 result[:summary] = summary if summary result[:description] = description if description end end end |