@@ -155,6 +155,27 @@ public final class Schema: Sendable {
155155 self . propertyOrdering = propertyOrdering
156156 }
157157
158+ /// Private initializer to create a new schema by copying an existing one with specific overrides.
159+ private convenience init ( copying other: Schema , nullable: Bool ? = nil ) {
160+ self . init (
161+ type: other. dataType,
162+ format: other. format,
163+ description: other. description,
164+ title: other. title,
165+ nullable: nullable ?? other. nullable,
166+ enumValues: other. enumValues,
167+ items: other. items,
168+ minItems: other. minItems,
169+ maxItems: other. maxItems,
170+ minimum: other. minimum,
171+ maximum: other. maximum,
172+ anyOf: other. anyOf,
173+ properties: other. properties,
174+ requiredProperties: other. requiredProperties,
175+ propertyOrdering: other. propertyOrdering
176+ )
177+ }
178+
158179 /// Returns a `Schema` representing a string value.
159180 ///
160181 /// This schema instructs the model to produce data of type `"STRING"`, which is suitable for
@@ -494,23 +515,6 @@ public extension Schema {
494515 /// `userSchema.nullable()`.
495516 ///
496517 /// - Returns: A new `Schema` instance with `nullable` set to `true`.
497- func asNullable( ) -> Schema {
498- return Schema (
499- type: dataType,
500- format: format,
501- description: description,
502- title: title,
503- nullable: true ,
504- enumValues: enumValues,
505- items: items,
506- minItems: minItems,
507- maxItems: maxItems,
508- minimum: minimum,
509- maximum: maximum,
510- anyOf: anyOf,
511- properties: properties,
512- requiredProperties: requiredProperties,
513- propertyOrdering: propertyOrdering
514- )
515- }
516- }
518+ func asNullable( ) -> Schema {
519+ return Schema ( copying: self , nullable: true )
520+ } }
0 commit comments