@@ -80,6 +80,12 @@ public final class Schema: Sendable {
80
80
/// Schema of the elements of type `"ARRAY"`.
81
81
public let items : Schema ?
82
82
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
+
83
89
/// Properties of type `"OBJECT"`.
84
90
public let properties : [ String : Schema ] ?
85
91
@@ -88,13 +94,16 @@ public final class Schema: Sendable {
88
94
89
95
required init ( type: DataType , format: String ? = nil , description: String ? = nil ,
90
96
nullable: Bool = false , enumValues: [ String ] ? = nil , items: Schema ? = nil ,
97
+ minItems: Int ? = nil , maxItems: Int ? = nil ,
91
98
properties: [ String : Schema ] ? = nil , requiredProperties: [ String ] ? = nil ) {
92
99
dataType = type
93
100
self . format = format
94
101
self . description = description
95
102
self . nullable = nullable
96
103
self . enumValues = enumValues
97
104
self . items = items
105
+ self . minItems = minItems
106
+ self . maxItems = maxItems
98
107
self . properties = properties
99
108
self . requiredProperties = requiredProperties
100
109
}
@@ -256,12 +265,23 @@ public final class Schema: Sendable {
256
265
/// - Parameters:
257
266
/// - items: The `Schema` of the elements that the array will hold.
258
267
/// - description: An optional description of what the array should contain or represent; may
259
- /// use Markdown format.
268
+ /// use Markdown format.
260
269
/// - 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
+ )
265
285
}
266
286
267
287
/// Returns a `Schema` representing an object.
@@ -327,6 +347,8 @@ extension Schema: Encodable {
327
347
case nullable
328
348
case enumValues = " enum "
329
349
case items
350
+ case minItems
351
+ case maxItems
330
352
case properties
331
353
case requiredProperties = " required "
332
354
}
0 commit comments