3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/geminai/schema_builder.rb', line 3
def self.build(schema)
case schema
when Symbol, String
{ type: normalize_type(schema) }
when Array
{ type: "array", items: build(schema.first) }
when Hash
if schema.key?(:type) || schema.key?("type")
normalized = schema.transform_keys(&:to_sym)
normalized[:properties] = normalized[:properties].transform_values { |v| build(v) } if normalized[:properties]
normalized[:items] = build(normalized[:items]) if normalized[:items]
normalized
else
properties = {}
required = []
schema.each do |key, val|
properties[key] = build(val)
required << key.to_s
end
{
type: "object",
properties: properties,
required: required
}
end
else
raise ArgumentError, "Unsupported schema format: #{schema.inspect}"
end
end
|