Class: MailSlurpClient::StructuredOutputSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/mailslurp_client/models/structured_output_schema.rb

Overview

JSON output schema for structured content repsonses. This schema dictates the format that an AI should use when responding to your instructions.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ StructuredOutputSchema

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 175

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `MailSlurpClient::StructuredOutputSchema` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `MailSlurpClient::StructuredOutputSchema`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'any_of')
    if (value = attributes[:'any_of']).is_a?(Array)
      self.any_of = value
    end
  end

  if attributes.key?(:'default')
    self.default = attributes[:'default']
  end

  if attributes.key?(:'description')
    self.description = attributes[:'description']
  end

  if attributes.key?(:'enum')
    if (value = attributes[:'enum']).is_a?(Array)
      self.enum = value
    end
  end

  if attributes.key?(:'example')
    self.example = attributes[:'example']
  end

  if attributes.key?(:'format')
    self.format = attributes[:'format']
  end

  if attributes.key?(:'items')
    self.items = attributes[:'items']
  end

  if attributes.key?(:'max_items')
    self.max_items = attributes[:'max_items']
  end

  if attributes.key?(:'min_items')
    self.min_items = attributes[:'min_items']
  end

  if attributes.key?(:'max_length')
    self.max_length = attributes[:'max_length']
  end

  if attributes.key?(:'min_length')
    self.min_length = attributes[:'min_length']
  end

  if attributes.key?(:'pattern')
    self.pattern = attributes[:'pattern']
  end

  if attributes.key?(:'properties')
    if (value = attributes[:'properties']).is_a?(Hash)
      self.properties = value
    end
  end

  if attributes.key?(:'property_ordering')
    if (value = attributes[:'property_ordering']).is_a?(Array)
      self.property_ordering = value
    end
  end

  if attributes.key?(:'required')
    if (value = attributes[:'required']).is_a?(Array)
      self.required = value
    end
  end

  if attributes.key?(:'max_properties')
    self.max_properties = attributes[:'max_properties']
  end

  if attributes.key?(:'min_properties')
    self.min_properties = attributes[:'min_properties']
  end

  if attributes.key?(:'maximum')
    self.maximum = attributes[:'maximum']
  end

  if attributes.key?(:'minimum')
    self.minimum = attributes[:'minimum']
  end

  if attributes.key?(:'nullable')
    self.nullable = attributes[:'nullable']
  end

  if attributes.key?(:'title')
    self.title = attributes[:'title']
  end

  if attributes.key?(:'type')
    self.type = attributes[:'type']
  end
end

Instance Attribute Details

#any_ofObject

Returns the value of attribute any_of.



18
19
20
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 18

def any_of
  @any_of
end

#defaultObject

Returns the value of attribute default.



20
21
22
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 20

def default
  @default
end

#descriptionObject

Provide a description of the schema to help the AI understand the schema.



23
24
25
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 23

def description
  @description
end

#enumObject

When using type string and format enum pass a collection of enum values here.



26
27
28
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 26

def enum
  @enum
end

#exampleObject

Returns the value of attribute example.



28
29
30
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 28

def example
  @example
end

#formatObject

Format for string types. Can be null, date-time or enum.



31
32
33
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 31

def format
  @format
end

#itemsObject

Returns the value of attribute items.



33
34
35
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 33

def items
  @items
end

#max_itemsObject

Returns the value of attribute max_items.



35
36
37
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 35

def max_items
  @max_items
end

#max_lengthObject

Returns the value of attribute max_length.



39
40
41
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 39

def max_length
  @max_length
end

#max_propertiesObject

Returns the value of attribute max_properties.



53
54
55
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 53

def max_properties
  @max_properties
end

#maximumObject

Returns the value of attribute maximum.



57
58
59
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 57

def maximum
  @maximum
end

#min_itemsObject

Returns the value of attribute min_items.



37
38
39
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 37

def min_items
  @min_items
end

#min_lengthObject

Returns the value of attribute min_length.



41
42
43
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 41

def min_length
  @min_length
end

#min_propertiesObject

Returns the value of attribute min_properties.



55
56
57
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 55

def min_properties
  @min_properties
end

#minimumObject

Returns the value of attribute minimum.



59
60
61
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 59

def minimum
  @minimum
end

#nullableObject

Returns the value of attribute nullable.



61
62
63
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 61

def nullable
  @nullable
end

#patternObject

Returns the value of attribute pattern.



43
44
45
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 43

def pattern
  @pattern
end

#propertiesObject

Properties of an OBJECT schema. These are key value pairs where the key is the property name and the value is the schema for that property.



46
47
48
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 46

def properties
  @properties
end

#property_orderingObject

Pass an array of property names to specify the order of properties in the generated JSON object if required.



49
50
51
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 49

def property_ordering
  @property_ordering
end

#requiredObject

Returns the value of attribute required.



51
52
53
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 51

def required
  @required
end

#titleObject

Returns the value of attribute title.



63
64
65
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 63

def title
  @title
end

#typeObject

Primitive JSON schema types with a fallback CUSTOM for unknown values.



66
67
68
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 66

def type
  @type
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



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
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 91

def self.attribute_map
  {
    :'any_of' => :'anyOf',
    :'default' => :'default',
    :'description' => :'description',
    :'enum' => :'enum',
    :'example' => :'example',
    :'format' => :'format',
    :'items' => :'items',
    :'max_items' => :'maxItems',
    :'min_items' => :'minItems',
    :'max_length' => :'maxLength',
    :'min_length' => :'minLength',
    :'pattern' => :'pattern',
    :'properties' => :'properties',
    :'property_ordering' => :'propertyOrdering',
    :'required' => :'required',
    :'max_properties' => :'maxProperties',
    :'min_properties' => :'minProperties',
    :'maximum' => :'maximum',
    :'minimum' => :'minimum',
    :'nullable' => :'nullable',
    :'title' => :'title',
    :'type' => :'type'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



446
447
448
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 446

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 147

def self.openapi_nullable
  Set.new([
    :'any_of',
    :'default',
    :'description',
    :'enum',
    :'example',
    :'format',
    :'max_items',
    :'min_items',
    :'max_length',
    :'min_length',
    :'pattern',
    :'properties',
    :'property_ordering',
    :'required',
    :'max_properties',
    :'min_properties',
    :'maximum',
    :'minimum',
    :'nullable',
    :'title',
    :'type'
  ])
end

.openapi_typesObject

Attribute type mapping.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 119

def self.openapi_types
  {
    :'any_of' => :'Array<StructuredOutputSchema>',
    :'default' => :'Object',
    :'description' => :'String',
    :'enum' => :'Array<String>',
    :'example' => :'Object',
    :'format' => :'String',
    :'items' => :'StructuredOutputSchema',
    :'max_items' => :'Integer',
    :'min_items' => :'Integer',
    :'max_length' => :'Integer',
    :'min_length' => :'Integer',
    :'pattern' => :'String',
    :'properties' => :'Hash<String, StructuredOutputSchema>',
    :'property_ordering' => :'Array<String>',
    :'required' => :'Array<String>',
    :'max_properties' => :'Integer',
    :'min_properties' => :'Integer',
    :'maximum' => :'Float',
    :'minimum' => :'Float',
    :'nullable' => :'Boolean',
    :'title' => :'String',
    :'type' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 404

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      any_of == o.any_of &&
      default == o.default &&
      description == o.description &&
      enum == o.enum &&
      example == o.example &&
      format == o.format &&
      items == o.items &&
      max_items == o.max_items &&
      min_items == o.min_items &&
      max_length == o.max_length &&
      min_length == o.min_length &&
      pattern == o.pattern &&
      properties == o.properties &&
      property_ordering == o.property_ordering &&
      required == o.required &&
      max_properties == o.max_properties &&
      min_properties == o.min_properties &&
      maximum == o.maximum &&
      minimum == o.minimum &&
      nullable == o.nullable &&
      title == o.title &&
      type == o.type
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 474

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    MailSlurpClient.const_get(type).build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 543

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 453

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


433
434
435
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 433

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



439
440
441
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 439

def hash
  [any_of, default, description, enum, example, format, items, max_items, min_items, max_length, min_length, pattern, properties, property_ordering, required, max_properties, min_properties, maximum, minimum, nullable, title, type].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 289

def list_invalid_properties
  invalid_properties = Array.new
  if !@max_items.nil? && @max_items < 0
    invalid_properties.push('invalid value for "max_items", must be greater than or equal to 0.')
  end

  if !@min_items.nil? && @min_items < 0
    invalid_properties.push('invalid value for "min_items", must be greater than or equal to 0.')
  end

  if !@max_length.nil? && @max_length < 0
    invalid_properties.push('invalid value for "max_length", must be greater than or equal to 0.')
  end

  if !@min_length.nil? && @min_length < 0
    invalid_properties.push('invalid value for "min_length", must be greater than or equal to 0.')
  end

  if !@max_properties.nil? && @max_properties < 0
    invalid_properties.push('invalid value for "max_properties", must be greater than or equal to 0.')
  end

  if !@min_properties.nil? && @min_properties < 0
    invalid_properties.push('invalid value for "min_properties", must be greater than or equal to 0.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



519
520
521
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 519

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 525

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end
    
    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



513
514
515
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 513

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



320
321
322
323
324
325
326
327
328
329
330
# File 'lib/mailslurp_client/models/structured_output_schema.rb', line 320

def valid?
  return false if !@max_items.nil? && @max_items < 0
  return false if !@min_items.nil? && @min_items < 0
  return false if !@max_length.nil? && @max_length < 0
  return false if !@min_length.nil? && @min_length < 0
  return false if !@max_properties.nil? && @max_properties < 0
  return false if !@min_properties.nil? && @min_properties < 0
  type_validator = EnumAttributeValidator.new('String', ["string", "number", "integer", "boolean", "object", "array", "null"])
  return false unless type_validator.valid?(@type)
  true
end