31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/firecrawlrb.rb', line 31
def self.normalize(input)
case input
when Hash
if input.key?(:type) || input.key?("type") || input.key?(:properties) || input.key?("properties")
input
else
properties = {}
input.each do |key, value|
properties[key.to_s] = normalize(value)
end
{
type: "object",
required: [],
properties: properties
}
end
when Array
if input.empty?
{ type: "array", items: { type: "string" } }
else
{ type: "array", items: normalize(input.first) }
end
when Symbol, String
type_str = input.to_s.downcase.to_sym
json_type = TYPE_MAPPING[type_str] || input.to_s
{ type: json_type }
else
{ type: "string" }
end
end
|