Class: JsonWorld::PropertyDefinition
- Inherits:
-
Object
- Object
- JsonWorld::PropertyDefinition
- Defined in:
- lib/json_world/property_definition.rb
Instance Attribute Summary collapse
- #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.
10 11 12 13 |
# File 'lib/json_world/property_definition.rb', line 10 def initialize(property_name: nil, **) @options = @property_name = property_name end |
Instance Attribute Details
#property_name ⇒ Symbol (readonly)
6 7 8 |
# File 'lib/json_world/property_definition.rb', line 6 def property_name @property_name end |
Instance Method Details
#as_json_schema ⇒ Hash{Symbol => Object}
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/json_world/property_definition.rb', line 16 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}
41 42 43 |
# File 'lib/json_world/property_definition.rb', line 41 def as_nested_json_schema { property_name => as_json_schema } end |
#optional? ⇒ false, true
Returns True if explicitly this property is defined as optional.
46 47 48 |
# File 'lib/json_world/property_definition.rb', line 46 def optional? !!@options[:optional] end |
#raw_options ⇒ Hash{Symbol => Object}
51 52 53 54 55 |
# File 'lib/json_world/property_definition.rb', line 51 def @options.merge( property_name: @property_name, ) end |