@@ -80,6 +80,12 @@ public final class Schema: Sendable {
8080 /// Schema of the elements of type `"ARRAY"`.
8181 public let items : Schema ?
8282
83+ /// The minimum number of items (elements) in a schema of type `"ARRAY"`.
84+ public let minItems : Int ?
85+
86+ /// The maximum number of items (elements) in a schema of type `"ARRAY"`.
87+ public let maxItems : Int ?
88+
8389 /// Properties of type `"OBJECT"`.
8490 public let properties : [ String : Schema ] ?
8591
@@ -88,13 +94,16 @@ public final class Schema: Sendable {
8894
8995 required init ( type: DataType , format: String ? = nil , description: String ? = nil ,
9096 nullable: Bool = false , enumValues: [ String ] ? = nil , items: Schema ? = nil ,
97+ minItems: Int ? = nil , maxItems: Int ? = nil ,
9198 properties: [ String : Schema ] ? = nil , requiredProperties: [ String ] ? = nil ) {
9299 dataType = type
93100 self . format = format
94101 self . description = description
95102 self . nullable = nullable
96103 self . enumValues = enumValues
97104 self . items = items
105+ self . minItems = minItems
106+ self . maxItems = maxItems
98107 self . properties = properties
99108 self . requiredProperties = requiredProperties
100109 }
@@ -256,12 +265,23 @@ public final class Schema: Sendable {
256265 /// - Parameters:
257266 /// - items: The `Schema` of the elements that the array will hold.
258267 /// - description: An optional description of what the array should contain or represent; may
259- /// use Markdown format.
268+ /// use Markdown format.
260269 /// - nullable: If `true`, instructs the model that it may return `null` instead of an array;
261- /// defaults to `false`, enforcing that an array is returned.
262- public static func array( items: Schema , description: String ? = nil ,
263- nullable: Bool = false ) -> Schema {
264- return self . init ( type: . array, description: description, nullable: nullable, items: items)
270+ /// defaults to `false`, enforcing that an array is returned.
271+ /// - minItems: Instructs the model to produce at least the specified minimum number of elements
272+ /// in the array; defaults to `nil`, meaning any number.
273+ /// - maxItems: Instructs the model to produce at most the specified maximum number of elements
274+ /// in the array.
275+ public static func array( items: Schema , description: String ? = nil , nullable: Bool = false ,
276+ minItems: Int ? = nil , maxItems: Int ? = nil ) -> Schema {
277+ return self . init (
278+ type: . array,
279+ description: description,
280+ nullable: nullable,
281+ items: items,
282+ minItems: minItems,
283+ maxItems: maxItems
284+ )
265285 }
266286
267287 /// Returns a `Schema` representing an object.
@@ -327,6 +347,8 @@ extension Schema: Encodable {
327347 case nullable
328348 case enumValues = " enum "
329349 case items
350+ case minItems
351+ case maxItems
330352 case properties
331353 case requiredProperties = " required "
332354 }
0 commit comments