Module: A2A::Extensions::AdditionalProperties::ClassMethods
- Defined in:
- lib/a2a/extensions/additional_properties.rb
Overview
Class methods added to the class that includes AdditionalProperties
Instance Method Summary collapse
-
#new(hash = nil) ⇒ Object
Override the new method to handle additional properties.
Instance Method Details
#new(hash = nil) ⇒ Object
Override the new method to handle additional properties
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/a2a/extensions/additional_properties.rb', line 84 def new(hash = nil) hash = {} if hash.nil? # Convert all keys to symbols input = hash.transform_keys(&:to_sym) # Get schema keys schema_keys = schema.keys.map(&:name) # Split input into schema data and additional properties schema_data = {} additional_props = {} input.each do |key, value| snake_key = INFLECTOR.underscore(key.to_s).to_sym if schema_keys.include?(snake_key) schema_data[snake_key] = value elsif schema_keys.include?(key) schema_data[key] = value else # Store additional properties with snake_case keys additional_props[snake_key] = value end end # Create instance using schema data instance = super(schema_data) # Attach additional properties instance.instance_variable_set(:@additional_properties, additional_props) instance end |