Class: Taro::Types::Field
- Inherits:
-
Data
- Object
- Data
- Taro::Types::Field
- Includes:
- FieldValueValidation, Shared::Errors, Shared::TypeClass
- Defined in:
- lib/taro/types/field.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#defined_at ⇒ Object
readonly
Returns the value of attribute defined_at.
-
#deprecated ⇒ Object
readonly
Returns the value of attribute deprecated.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#null ⇒ Object
readonly
Returns the value of attribute null.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #default_specified? ⇒ Boolean
-
#initialize(name:, type:, default: Taro::None, defined_at: nil, deprecated: nil, desc: nil, enum: nil, method: name, null: Taro.config.default_value_for_null, required: default == Taro::None ? Taro.config.default_value_for_required : false) ⇒ Field
constructor
A new instance of Field.
- #openapi_format ⇒ Object
- #openapi_type ⇒ Object
- #value_for_input(object) ⇒ Object
- #value_for_response(object, context: nil, object_is_hash: true) ⇒ Object
Methods included from Shared::TypeClass
Methods included from Shared::Errors
#coerce_error_message, #input_error, #response_error
Methods included from FieldValueValidation
Constructor Details
#initialize(name:, type:, default: Taro::None, defined_at: nil, deprecated: nil, desc: nil, enum: nil, method: name, null: Taro.config.default_value_for_null, required: default == Taro::None ? Taro.config.default_value_for_required : false) ⇒ Field
Returns a new instance of Field.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/taro/types/field.rb', line 11 def initialize( name:, type:, default: Taro::None, defined_at: nil, deprecated: nil, desc: nil, enum: nil, method: name, # note: `method` is stored as #resolver to avoid overriding Object#method null: Taro.config.default_value_for_null, required: default == Taro::None ? Taro.config.default_value_for_required : false ) enum = coerce_to_enum(enum) super( name:, type:, default:, defined_at:, deprecated: (true if deprecated), desc:, enum:, null: !!null, required: !!required, resolver: method, ) end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def default @default end |
#defined_at ⇒ Object (readonly)
Returns the value of attribute defined_at
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def defined_at @defined_at end |
#deprecated ⇒ Object (readonly)
Returns the value of attribute deprecated
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def deprecated @deprecated end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def desc @desc end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def enum @enum end |
#name ⇒ Object (readonly)
Returns the value of attribute name
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def name @name end |
#null ⇒ Object (readonly)
Returns the value of attribute null
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def null @null end |
#required ⇒ Object (readonly)
Returns the value of attribute required
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def required @required end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def resolver @resolver end |
#type ⇒ Object (readonly)
Returns the value of attribute type
3 4 5 |
# File 'lib/taro/types/field.rb', line 3 def type @type end |
Instance Method Details
#default_specified? ⇒ Boolean
58 59 60 |
# File 'lib/taro/types/field.rb', line 58 def default_specified? !default.equal?(Taro::None) end |
#openapi_format ⇒ Object
66 67 68 |
# File 'lib/taro/types/field.rb', line 66 def openapi_format type.openapi_format end |
#openapi_type ⇒ Object
62 63 64 |
# File 'lib/taro/types/field.rb', line 62 def openapi_type type.openapi_type end |
#value_for_input(object) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/taro/types/field.rb', line 38 def value_for_input(object) unless object&.key?(name) fail_if_required return default_specified? ? default : Taro::None end value = object[name] value = coerce_value(value, true) validated_value(value) rescue Taro::ValidationError => e reraise_recursively_with_path_info(e) end |
#value_for_response(object, context: nil, object_is_hash: true) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/taro/types/field.rb', line 50 def value_for_response(object, context: nil, object_is_hash: true) value = retrieve_response_value(object, context, object_is_hash) value = coerce_value(value, false) validated_value(value, false) rescue Taro::ValidationError => e reraise_recursively_with_path_info(e) end |