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
Defined Under Namespace
Classes: Resolver
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, deep: true) ⇒ Object
Resolves the reference by looking up the referred object in
definitions. -
#resolve_lazily(definitions) ⇒ Object
Lazily resolves the reference.
-
#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
#attributes_frozen?, #freeze_attributes, included
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.
35 36 37 |
# File 'lib/jsapi/meta/model/reference.rb', line 35 def component_type @component_type ||= name.split('::')[-2].underscore end |
.openapi_component_type ⇒ Object
Derrives the OpenAPI component type from the inner most module name.
40 41 42 |
# File 'lib/jsapi/meta/model/reference.rb', line 40 def 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.
50 |
# File 'lib/jsapi/meta/model/reference.rb', line 50 attribute :description, String |
#ref ⇒ Object
:attr: ref The name of the referred object.
55 |
# File 'lib/jsapi/meta/model/reference.rb', line 55 attribute :ref, String |
#reference? ⇒ Boolean
Returns true.
65 66 67 |
# File 'lib/jsapi/meta/model/reference.rb', line 65 def reference? true end |
#resolve(definitions, deep: true) ⇒ Object
Resolves the reference by looking up the referred object in definitions.
Raises a ReferenceError if the reference could not be resolved.
72 73 74 75 76 77 |
# File 'lib/jsapi/meta/model/reference.rb', line 72 def resolve(definitions, deep: true) object = definitions.send("find_#{self.class.component_type}", ref) raise ReferenceError, ref if object.nil? deep ? object.resolve(definitions, deep: true) : object end |
#resolve_lazily(definitions) ⇒ Object
Lazily resolves the reference.
Raises a ReferenceError if the reference could not be resolved.
82 83 84 |
# File 'lib/jsapi/meta/model/reference.rb', line 82 def resolve_lazily(definitions) Resolver.new(self, 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.
62 |
# File 'lib/jsapi/meta/model/reference.rb', line 62 attribute :summary, String |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI reference object.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jsapi/meta/model/reference.rb', line 87 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 |