Class: Jsapi::Meta::Property
Instance Method Summary collapse
-
#initialize(name, keywords = {}) ⇒ Property
constructor
Creates a new property.
-
#name ⇒ Object
:attr_reader: name The name of the property.
-
#read_only ⇒ Object
:attr: read_only.
-
#required? ⇒ Boolean
Returns true if the level of existence is greater than or equal to
ALLOW_NIL
, false otherwise. -
#schema ⇒ Object
:attr_reader: schema The Schema of the parameter.
-
#source ⇒ Object
:attr: source The alternative method to read a property value when serializing an object.
-
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI schema object.
-
#write_only ⇒ Object
:attr: write_only.
Methods inherited from Base
#inspect, #reference?, #resolve
Methods included from Attributes::ClassMethods
Constructor Details
#initialize(name, keywords = {}) ⇒ Property
Creates a new property.
Raises an ArgumentError
if name
is blank.
35 36 37 38 39 40 41 42 43 |
# File 'lib/jsapi/meta/property.rb', line 35 def initialize(name, keywords = {}) raise ArgumentError, "property name can't be blank" if name.blank? keywords = keywords.dup super(keywords.extract!(:read_only, :source, :write_only)) @name = name.to_s @schema = Schema.new(keywords) end |
Instance Method Details
#name ⇒ Object
:attr_reader: name The name of the property.
9 |
# File 'lib/jsapi/meta/property.rb', line 9 attribute :name, writer: false |
#read_only ⇒ Object
:attr: read_only
13 |
# File 'lib/jsapi/meta/property.rb', line 13 attribute :read_only, values: [true, false] |
#required? ⇒ Boolean
Returns true if the level of existence is greater than or equal to ALLOW_NIL
, false otherwise.
47 48 49 |
# File 'lib/jsapi/meta/property.rb', line 47 def required? schema.existence >= Existence::ALLOW_NIL end |
#schema ⇒ Object
:attr_reader: schema The Schema of the parameter.
18 |
# File 'lib/jsapi/meta/property.rb', line 18 attribute :schema, writer: false |
#source ⇒ Object
:attr: source The alternative method to read a property value when serializing an object.
24 |
# File 'lib/jsapi/meta/property.rb', line 24 attribute :source, Symbol |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI schema object.
52 53 54 55 56 57 58 59 |
# File 'lib/jsapi/meta/property.rb', line 52 def to_openapi(version) version = OpenAPI::Version.from(version) schema.to_openapi(version).tap do |hash| hash[:readOnly] = true if read_only? hash[:writeOnly] = true if write_only? && version.major > 2 end end |
#write_only ⇒ Object
:attr: write_only
28 |
# File 'lib/jsapi/meta/property.rb', line 28 attribute :write_only, values: [true, false] |