Skip to content

Add title parameter to all static functions in Schema class #14971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 13, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions FirebaseAI/Sources/Types/Public/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,21 @@ public final class Schema: Sendable {
/// - Parameters:
/// - description: An optional description of what the string should contain or represent; may
/// use Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it *may* generate `null` instead of a
/// string; defaults to `false`, enforcing that a string value is generated.
/// - format: An optional modifier describing the expected format of the string. Currently no
/// formats are officially supported for strings but custom values may be specified using
/// ``StringFormat/custom(_:)``, for example `.custom("email")` or `.custom("byte")`; these
/// provide additional hints for how the model should respond but are not guaranteed to be
/// adhered to.
public static func string(description: String? = nil, nullable: Bool = false,
format: StringFormat? = nil) -> Schema {
public static func string(description: String? = nil, title: String? = nil,
nullable: Bool = false, format: StringFormat? = nil) -> Schema {
return self.init(
type: .string,
format: format?.rawValue,
description: description,
title: title,
nullable: nullable
)
}
Expand All @@ -202,15 +204,17 @@ public final class Schema: Sendable {
/// - values: The list of string values that may be generated by the model.
/// - description: An optional description of what the `values` contain or represent; may use
/// Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it *may* generate `null` instead of one of
/// the strings specified in `values`; defaults to `false`, enforcing that one of the string
/// values is generated.
public static func enumeration(values: [String], description: String? = nil,
nullable: Bool = false) -> Schema {
title: String? = nil, nullable: Bool = false) -> Schema {
return self.init(
type: .string,
format: "enum",
description: description,
title: title,
nullable: nullable,
enumValues: values
)
Expand All @@ -229,18 +233,20 @@ public final class Schema: Sendable {
/// - Parameters:
/// - description: An optional description of what the number should contain or represent; may
/// use Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it may generate `null` instead of a number;
/// defaults to `false`, enforcing that a number is generated.
/// - minimum: If specified, instructs the model that the value should be greater than or
/// equal to the specified minimum.
/// - maximum: If specified, instructs the model that the value should be less than or equal
/// to the specified maximum.
public static func float(description: String? = nil, nullable: Bool = false,
public static func float(description: String? = nil, title: String? = nil, nullable: Bool = false,
minimum: Float? = nil, maximum: Float? = nil) -> Schema {
return self.init(
type: .number,
format: "float",
description: description,
title: title,
nullable: nullable,
minimum: minimum.map { Double($0) },
maximum: maximum.map { Double($0) }
Expand All @@ -255,17 +261,20 @@ public final class Schema: Sendable {
/// - Parameters:
/// - description: An optional description of what the number should contain or represent; may
/// use Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it may return `null` instead of a number;
/// defaults to `false`, enforcing that a number is returned.
/// - minimum: If specified, instructs the model that the value should be greater than or
/// equal to the specified minimum.
/// - maximum: If specified, instructs the model that the value should be less than or equal
/// to the specified maximum.
public static func double(description: String? = nil, nullable: Bool = false,
public static func double(description: String? = nil, title: String? = nil,
nullable: Bool = false,
minimum: Double? = nil, maximum: Double? = nil) -> Schema {
return self.init(
type: .number,
description: description,
title: title,
nullable: nullable,
minimum: minimum,
maximum: maximum
Expand All @@ -287,6 +296,7 @@ public final class Schema: Sendable {
/// - Parameters:
/// - description: An optional description of what the integer should contain or represent; may
/// use Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it may return `null` instead of an integer;
/// defaults to `false`, enforcing that an integer is returned.
/// - format: An optional modifier describing the expected format of the integer. Currently the
Expand All @@ -296,13 +306,14 @@ public final class Schema: Sendable {
/// equal to the specified minimum.
/// - maximum: If specified, instructs the model that the value should be less than or equal
/// to the specified maximum.
public static func integer(description: String? = nil, nullable: Bool = false,
format: IntegerFormat? = nil,
public static func integer(description: String? = nil, title: String? = nil,
nullable: Bool = false, format: IntegerFormat? = nil,
minimum: Int? = nil, maximum: Int? = nil) -> Schema {
return self.init(
type: .integer,
format: format?.rawValue,
description: description,
title: title,
nullable: nullable.self,
minimum: minimum.map { Double($0) },
maximum: maximum.map { Double($0) }
Expand All @@ -317,10 +328,12 @@ public final class Schema: Sendable {
/// - Parameters:
/// - description: An optional description of what the boolean should contain or represent; may
/// use Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it may return `null` instead of a boolean;
/// defaults to `false`, enforcing that a boolean is returned.
public static func boolean(description: String? = nil, nullable: Bool = false) -> Schema {
return self.init(type: .boolean, description: description, nullable: nullable)
public static func boolean(description: String? = nil, title: String? = nil,
nullable: Bool = false) -> Schema {
return self.init(type: .boolean, description: description, title: title, nullable: nullable)
}

/// Returns a `Schema` representing an array.
Expand All @@ -334,17 +347,20 @@ public final class Schema: Sendable {
/// - items: The `Schema` of the elements that the array will hold.
/// - description: An optional description of what the array should contain or represent; may
/// use Markdown format.
/// - title: An optional human-readable name/summary for the object schema.
/// - nullable: If `true`, instructs the model that it may return `null` instead of an array;
/// defaults to `false`, enforcing that an array is returned.
/// - minItems: Instructs the model to produce at least the specified minimum number of elements
/// in the array; defaults to `nil`, meaning any number.
/// - maxItems: Instructs the model to produce at most the specified maximum number of elements
/// in the array.
public static func array(items: Schema, description: String? = nil, nullable: Bool = false,
minItems: Int? = nil, maxItems: Int? = nil) -> Schema {
public static func array(items: Schema, description: String? = nil, title: String? = nil,
nullable: Bool = false, minItems: Int? = nil,
maxItems: Int? = nil) -> Schema {
return self.init(
type: .array,
description: description,
title: title,
nullable: nullable,
items: items,
minItems: minItems,
Expand Down
Loading