@@ -68,44 +68,77 @@ public final class Schema: Sendable {
6868 /// The format of the data.
6969 public let format : String ?
7070
71- /// A brief description of the parameter.
71+ /// A human-readable explanation of the purpose of the schema or property. While not strictly
72+ /// enforced on the value itself, good descriptions significantly help the model understand the
73+ /// context and generate more relevant and accurate output.
7274 public let description : String ?
7375
76+ /// A human-readable name/summary for the schema or a specific property. This helps document the
77+ /// schema's purpose but doesn't typically constrain the generated value. It can subtly guide the
78+ /// model by clarifying the intent of a field.
79+ public let title : String ?
80+
7481 /// Indicates if the value may be null.
7582 public let nullable : Bool ?
7683
7784 /// Possible values of the element of type "STRING" with "enum" format.
7885 public let enumValues : [ String ] ?
7986
80- /// Schema of the elements of type `"ARRAY"`.
87+ /// Defines the schema for the elements within the `"ARRAY"`. All items in the generated array
88+ /// must conform to this schema definition. This can be a simple type (like .string) or a complex
89+ /// nested object schema.
8190 public let items : Schema ?
8291
83- /// The minimum number of items (elements) in a schema of type `"ARRAY"`.
92+ /// An integer specifying the minimum number of items the generated `"ARRAY"` must contain .
8493 public let minItems : Int ?
8594
86- /// The maximum number of items (elements) in a schema of type `"ARRAY"`.
95+ /// An integer specifying the maximum number of items the generated `"ARRAY"` must contain .
8796 public let maxItems : Int ?
8897
89- /// Properties of type `"OBJECT"`.
98+ /// The minimum value of a numeric type.
99+ public let minimum : Double ?
100+
101+ /// The maximum value of a numeric type.
102+ public let maximum : Double ?
103+
104+ /// Defines the members (key-value pairs) expected within an object. It's a dictionary where keys
105+ /// are the property names (strings) and values are nested `Schema` definitions describing each
106+ /// property's type and constraints.
90107 public let properties : [ String : Schema ] ?
91108
92- /// Required properties of type `"OBJECT"`.
109+ /// An array of strings, where each string is the name of a property defined in the `properties`
110+ /// dictionary that must be present in the generated object. If a property is listed here, the
111+ /// model must include it in the output.
93112 public let requiredProperties : [ String ] ?
94113
114+ /// A specific hint provided to the Gemini model, suggesting the order in which the keys should
115+ /// appear in the generated JSON string. Important: Standard JSON objects are inherently unordered
116+ /// collections of key-value pairs. While the model will try to respect propertyOrdering in its
117+ /// textual JSON output, subsequent parsing into native Swift objects (like Dictionaries or
118+ /// Structs) might not preserve this order. This parameter primarily affects the raw JSON string
119+ /// serialization.
120+ public let propertyOrdering : [ String ] ?
121+
95122 required init ( type: DataType , format: String ? = nil , description: String ? = nil ,
123+ title: String ? = nil ,
96124 nullable: Bool = false , enumValues: [ String ] ? = nil , items: Schema ? = nil ,
97- minItems: Int ? = nil , maxItems: Int ? = nil ,
98- properties: [ String : Schema ] ? = nil , requiredProperties: [ String ] ? = nil ) {
125+ minItems: Int ? = nil , maxItems: Int ? = nil , minimum: Double ? = nil ,
126+ maximum: Double ? = nil , properties: [ String : Schema ] ? = nil ,
127+ requiredProperties: [ String ] ? = nil , propertyOrdering: [ String ] ? = nil ) {
99128 dataType = type
100129 self . format = format
101130 self . description = description
131+ self . title = title
102132 self . nullable = nullable
103133 self . enumValues = enumValues
104134 self . items = items
105135 self . minItems = minItems
106136 self . maxItems = maxItems
137+ self . minimum = minimum
138+ self . maximum = maximum
107139 self . properties = properties
108140 self . requiredProperties = requiredProperties
141+ self . propertyOrdering = propertyOrdering
109142 }
110143
111144 /// Returns a `Schema` representing a string value.
@@ -184,12 +217,19 @@ public final class Schema: Sendable {
184217 /// use Markdown format.
185218 /// - nullable: If `true`, instructs the model that it may generate `null` instead of a number;
186219 /// defaults to `false`, enforcing that a number is generated.
187- public static func float( description: String ? = nil , nullable: Bool = false ) -> Schema {
220+ /// - minimum: If specified, instructs the model that the value should be greater than or
221+ /// equal to the specified minimum.
222+ /// - maximum: If specified, instructs the model that the value should be less than or equal
223+ /// to the specified maximum.
224+ public static func float( description: String ? = nil , nullable: Bool = false ,
225+ minimum: Float ? = nil , maximum: Float ? = nil ) -> Schema {
188226 return self . init (
189227 type: . number,
190228 format: " float " ,
191229 description: description,
192- nullable: nullable
230+ nullable: nullable,
231+ minimum: minimum. map { Double ( $0) } ,
232+ maximum: maximum. map { Double ( $0) }
193233 )
194234 }
195235
@@ -203,11 +243,18 @@ public final class Schema: Sendable {
203243 /// use Markdown format.
204244 /// - nullable: If `true`, instructs the model that it may return `null` instead of a number;
205245 /// defaults to `false`, enforcing that a number is returned.
206- public static func double( description: String ? = nil , nullable: Bool = false ) -> Schema {
246+ /// - minimum: If specified, instructs the model that the value should be greater than or
247+ /// equal to the specified minimum.
248+ /// - maximum: If specified, instructs the model that the value should be less than or equal
249+ /// to the specified maximum.
250+ public static func double( description: String ? = nil , nullable: Bool = false ,
251+ minimum: Double ? = nil , maximum: Double ? = nil ) -> Schema {
207252 return self . init (
208253 type: . number,
209254 description: description,
210- nullable: nullable
255+ nullable: nullable,
256+ minimum: minimum,
257+ maximum: maximum
211258 )
212259 }
213260
@@ -232,12 +279,15 @@ public final class Schema: Sendable {
232279 /// formats ``IntegerFormat/int32`` and ``IntegerFormat/int64`` are supported; custom values
233280 /// may be specified using ``IntegerFormat/custom(_:)`` but may be ignored by the model.
234281 public static func integer( description: String ? = nil , nullable: Bool = false ,
235- format: IntegerFormat ? = nil ) -> Schema {
282+ format: IntegerFormat ? = nil ,
283+ minimum: Int ? = nil , maximum: Int ? = nil ) -> Schema {
236284 return self . init (
237285 type: . integer,
238286 format: format? . rawValue,
239287 description: description,
240- nullable: nullable
288+ nullable: nullable. self,
289+ minimum: minimum. map { Double ( $0) } ,
290+ maximum: maximum. map { Double ( $0) }
241291 )
242292 }
243293
@@ -317,7 +367,9 @@ public final class Schema: Sendable {
317367 /// - nullable: If `true`, instructs the model that it may return `null` instead of an object;
318368 /// defaults to `false`, enforcing that an object is returned.
319369 public static func object( properties: [ String : Schema ] , optionalProperties: [ String ] = [ ] ,
320- description: String ? = nil , nullable: Bool = false ) -> Schema {
370+ propertyOrdering: [ String ] ? = nil ,
371+ description: String ? = nil , title: String ? = nil ,
372+ nullable: Bool = false ) -> Schema {
321373 var requiredProperties = Set ( properties. keys)
322374 for optionalProperty in optionalProperties {
323375 guard properties. keys. contains ( optionalProperty) else {
@@ -329,9 +381,11 @@ public final class Schema: Sendable {
329381 return self . init (
330382 type: . object,
331383 description: description,
384+ title: title,
332385 nullable: nullable,
333386 properties: properties,
334- requiredProperties: requiredProperties. sorted ( )
387+ requiredProperties: requiredProperties. sorted ( ) ,
388+ propertyOrdering: propertyOrdering
335389 )
336390 }
337391}
@@ -344,12 +398,16 @@ extension Schema: Encodable {
344398 case dataType = " type "
345399 case format
346400 case description
401+ case title
347402 case nullable
348403 case enumValues = " enum "
349404 case items
350405 case minItems
351406 case maxItems
407+ case minimum
408+ case maximum
352409 case properties
353410 case requiredProperties = " required "
411+ case propertyOrdering
354412 }
355413}
0 commit comments