Class: JsonWorld::PropertyDefinition
- Inherits:
-
Object
- Object
- JsonWorld::PropertyDefinition
- Defined in:
- lib/json_world/property_definition.rb
Instance Attribute Summary collapse
- #options ⇒ Hash{Symbol => Object} readonly
- #property_name ⇒ Symbol readonly
Instance Method Summary collapse
- #as_json_schema ⇒ Hash{Symbol => Object}
- #as_nested_json_schema ⇒ Hash{Symbol => Object}
-
#initialize(property_name: nil, **options) ⇒ PropertyDefinition
constructor
A new instance of PropertyDefinition.
-
#optional? ⇒ false, true
True if explicitly this property is defined as optional.
- #raw_options ⇒ Hash{Symbol => Object}
Constructor Details
#initialize(property_name: nil, **options) ⇒ PropertyDefinition
Returns a new instance of PropertyDefinition.
13 14 15 16 |
# File 'lib/json_world/property_definition.rb', line 13 def initialize(property_name: nil, **) @options = @property_name = property_name end |
Instance Attribute Details
#options ⇒ Hash{Symbol => Object} (readonly)
6 7 8 |
# File 'lib/json_world/property_definition.rb', line 6 def @options end |
#property_name ⇒ Symbol (readonly)
9 10 11 |
# File 'lib/json_world/property_definition.rb', line 9 def property_name @property_name end |
Instance Method Details
#as_json_schema ⇒ Hash{Symbol => Object}
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/json_world/property_definition.rb', line 19 def as_json_schema if has_json_schema_compatible_type? if @options[:links] @options[:type].as_json_schema else @options[:type].as_json_schema_without_links end else { description: description, example: example, format: format_type, items: items_as_json_schema, pattern: pattern_in_string, properties: properties_as_json_schema, required: required_property_names, type: type, uniqueItems: unique_flag, }.reject do |_key, value| value.nil? || value.respond_to?(:empty?) && value.empty? end end end |
#as_nested_json_schema ⇒ Hash{Symbol => Object}
44 45 46 |
# File 'lib/json_world/property_definition.rb', line 44 def as_nested_json_schema { property_name => as_json_schema } end |
#optional? ⇒ false, true
Returns True if explicitly this property is defined as optional.
49 50 51 |
# File 'lib/json_world/property_definition.rb', line 49 def optional? !!@options[:optional] end |
#raw_options ⇒ Hash{Symbol => Object}
54 55 56 57 58 |
# File 'lib/json_world/property_definition.rb', line 54 def @options.merge( property_name: @property_name, ) end |