Module: OmniAI::Schema
- Defined in:
- lib/omniai/schema.rb,
lib/omniai/schema/base.rb,
lib/omniai/schema/array.rb,
lib/omniai/schema/format.rb,
lib/omniai/schema/object.rb,
lib/omniai/schema/scalar.rb
Overview
Defined Under Namespace
Classes: Array, Base, Format, Object, Scalar
Class Method Summary
collapse
-
.array(items:, min_items: nil, max_items: nil, description: nil, nullable: nil) ⇒ OmniAI::Schema::Array
-
.boolean(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
-
.build(kind, **args) ⇒ OmniAI::Schema::Object, ...
-
.deserialize(data) ⇒ Object
-
.format(name:, schema:) ⇒ OmniAI::Schema::Format
-
.integer(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
-
.number(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
-
.object(title: nil, properties: {}, required: [], description: nil, nullable: nil) ⇒ OmniAI::Schema::Array
-
.string(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
Class Method Details
.array(items:, min_items: nil, max_items: nil, description: nil, nullable: nil) ⇒ OmniAI::Schema::Array
88
89
90
|
# File 'lib/omniai/schema.rb', line 88
def self.array(items:, min_items: nil, max_items: nil, description: nil, nullable: nil)
OmniAI::Schema::Array.new(items:, description:, min_items:, max_items:, nullable:)
end
|
.boolean(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
123
124
125
|
# File 'lib/omniai/schema.rb', line 123
def self.boolean(title: nil, description: nil, enum: nil, nullable: nil)
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::BOOLEAN, title:, description:, enum:, nullable:)
end
|
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/omniai/schema.rb', line 62
def self.build(kind, **args)
case kind
when :array then array(**args)
when :object then object(**args)
when :boolean then boolean(**args)
when :integer then integer(**args)
when :number then number(**args)
when :string then string(**args)
end
end
|
.deserialize(data) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/omniai/schema.rb', line 49
def self.deserialize(data)
type = Array(data["type"] || data[:type]).find { |type| !type.eql?("null") }
case type
when OmniAI::Schema::Array::TYPE then OmniAI::Schema::Array.deserialize(data)
when OmniAI::Schema::Object::TYPE then OmniAI::Schema::Object.deserialize(data)
else OmniAI::Schema::Scalar.deserialize(data)
end
end
|
174
175
176
|
# File 'lib/omniai/schema.rb', line 174
def self.format(name:, schema:)
OmniAI::Schema::Format.new(name:, schema:)
end
|
.integer(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
136
137
138
|
# File 'lib/omniai/schema.rb', line 136
def self.integer(title: nil, description: nil, enum: nil, nullable: nil)
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::INTEGER, title:, description:, enum:, nullable:)
end
|
.number(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
162
163
164
|
# File 'lib/omniai/schema.rb', line 162
def self.number(title: nil, description: nil, enum: nil, nullable: nil)
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::NUMBER, title:, description:, enum:, nullable:)
end
|
.object(title: nil, properties: {}, required: [], description: nil, nullable: nil) ⇒ OmniAI::Schema::Array
110
111
112
|
# File 'lib/omniai/schema.rb', line 110
def self.object(title: nil, properties: {}, required: [], description: nil, nullable: nil)
OmniAI::Schema::Object.new(title:, properties:, required:, description:, nullable:)
end
|
.string(title: nil, description: nil, enum: nil, nullable: nil) ⇒ OmniAI::Schema::Scalar
149
150
151
|
# File 'lib/omniai/schema.rb', line 149
def self.string(title: nil, description: nil, enum: nil, nullable: nil)
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::STRING, title:, description:, enum:, nullable:)
end
|