Skip to content

Commit f931ce6

Browse files
committed
more review feedback
1 parent f56a133 commit f931ce6

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

FirebaseAI/Sources/Types/Public/Schema.swift

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}}

FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,21 @@ struct GenerateContentIntegrationTests {
143143
func generateContentJSONObject(_ config: InstanceConfig) async throws {
144144
struct Recipe: Codable {
145145
let name: String
146-
let ingredients: [Ingredient]
146+
let ingredients: [RecipeIngredient]
147147
let isDelicious: Bool
148148
}
149149

150-
struct Ingredient: Codable, Equatable {
150+
struct RecipeIngredient: Codable, Equatable {
151151
let name: String
152152
let quantity: Int
153153
}
154154

155155
let expectedResponse = Recipe(
156156
name: "Apple Pie",
157157
ingredients: [
158-
Ingredient(name: "Apple", quantity: 6),
159-
Ingredient(name: "Cinnamon", quantity: 1),
160-
Ingredient(name: "Sugar", quantity: 1),
158+
RecipeIngredient(name: "Apple", quantity: 6),
159+
RecipeIngredient(name: "Cinnamon", quantity: 1),
160+
RecipeIngredient(name: "Sugar", quantity: 1),
161161
],
162162
isDelicious: true
163163
)

0 commit comments

Comments
 (0)