Skip to content

Commit 52d9851

Browse files
committed
Add DocC comments for the numeric and string static methods
1 parent 079b00c commit 52d9851

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

FirebaseVertexAI/Sources/Schema.swift

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ public class Schema {
102102
self.requiredProperties = requiredProperties
103103
}
104104

105+
/// Returns a `Schema` representing a string value.
106+
///
107+
/// This schema instructs the model to produce data of type ``DataType/string``, which is suitable
108+
/// for decoding as a Swift `String` (or `String?`, if ``nullable`` is set to `true`).
109+
///
110+
/// > Tip: If a specific set of string values should be generated by the model (for example,
111+
/// > "north", "south", "east", or "west"), use ``enumeration(values:description:nullable:)``
112+
/// > instead to constrain the generated values.
113+
///
114+
/// - Parameters:
115+
/// - description: An optional description of what the string should contain or represent; may
116+
/// use Markdown format.
117+
/// - nullable: If `true`, instructs the model that it *may* generate `null` instead of a
118+
/// string; defaults to `false`, enforcing that a string value is generated.
119+
/// - format: An optional modifier describing the expected format of the string. Currently no
120+
/// formats are officially supported for strings but custom values may be specified using
121+
/// ``StringFormat/custom(_:)``, for example `.custom("email")` or `.custom("byte")`; these
122+
/// provide additional hints for how the model should respond but are not guaranteed to be
123+
/// adhered to.
105124
public static func string(description: String? = nil, nullable: Bool = false,
106125
format: StringFormat? = nil) -> Schema {
107126
return self.init(
@@ -112,6 +131,27 @@ public class Schema {
112131
)
113132
}
114133

134+
/// Returns a `Schema` representing an enumeration of string values.
135+
///
136+
/// This schema instructs the model to produce data of type ``DataType/string`` with the
137+
/// ``format`` `"enum"`. This data is suitable for decoding as a Swift `String` (or `String?`,
138+
/// if ``nullable`` is set to `true`), or an `enum` with strings as raw values.
139+
///
140+
/// **Example:**
141+
/// The values `["north", "south", "east", "west"]` for an enumation of directions.
142+
/// ```
143+
/// enum Direction: String, Decodable {
144+
/// case north, south, east, west
145+
/// }
146+
/// ```
147+
///
148+
/// - Parameters:
149+
/// - values: The list of string values that may be generated by the model.
150+
/// - description: An optional description of what the `values` contain or represent; may use
151+
/// Markdown format.
152+
/// - nullable: If `true`, instructs the model that it *may* generate `null` instead of one of
153+
/// the strings specified in `values`; defaults to `false`, enforcing that one of the string
154+
/// values is generated.
115155
public static func enumeration(values: [String], description: String? = nil,
116156
nullable: Bool = false) -> Schema {
117157
return self.init(
@@ -123,6 +163,21 @@ public class Schema {
123163
)
124164
}
125165

166+
/// Returns a `Schema` representing a single-precision floating-point number.
167+
///
168+
/// This schema instructs the model to produce data of type ``DataType/number`` with the
169+
/// ``format`` `"float"`, which is suitable for decoding as a Swift `Float` (or `Float?`, if
170+
/// ``nullable`` is set to `true`).
171+
///
172+
/// > Important: This `Schema` provides a hint to the model that it should generate a
173+
/// > single-precision floating-point number, a `float`, but only guarantees that the value will
174+
/// > be a number.
175+
///
176+
/// - Parameters:
177+
/// - description: An optional description of what the number should contain or represent; may
178+
/// use Markdown format.
179+
/// - nullable: If `true`, instructs the model that it may generate `null` instead of a number;
180+
/// defaults to `false`, enforcing that a number is generated.
126181
public static func float(description: String? = nil, nullable: Bool = false) -> Schema {
127182
return self.init(
128183
type: .number,
@@ -132,6 +187,21 @@ public class Schema {
132187
)
133188
}
134189

190+
/// Returns a `Schema` representing a double-precision floating-point number.
191+
///
192+
/// This schema instructs the model to produce data of type ``DataType/number`` with the
193+
/// ``format`` `"double"`, which is suitable for decoding as a Swift `Double` (or `Double?`, if
194+
/// ``nullable`` is set to `true`).
195+
///
196+
/// > Important: This `Schema` provides a hint to the model that it should generate a
197+
/// > double-precision floating-point number, a `double`, but only guarantees that the value will
198+
/// > be a number.
199+
///
200+
/// - Parameters:
201+
/// - description: An optional description of what the number should contain or represent; may
202+
/// use Markdown format.
203+
/// - nullable: If `true`, instructs the model that it may return `null` instead of a number;
204+
/// defaults to `false`, enforcing that a number is returned.
135205
public static func double(description: String? = nil, nullable: Bool = false) -> Schema {
136206
return self.init(
137207
type: .number,
@@ -141,6 +211,26 @@ public class Schema {
141211
)
142212
}
143213

214+
/// Returns a `Schema` representing an integer value.
215+
///
216+
/// This schema instructs the model to produce data of type ``DataType/integer``, which is
217+
/// suitable for decoding as a Swift `Int` (or `Int?`, if ``nullable`` is set to `true`) or other
218+
/// integer types (such as `Int32`) based on the expected size of values being generated.
219+
///
220+
/// > Important: If a ``format`` of ``IntegerFormat/int32`` or ``IntegerFormat/int64`` is
221+
/// > specified, this provides a hint to the model that it should generate 32-bit or 64-bit
222+
/// > integers but this `Schema` only guarantees that the value will be an integer. Therefore, it
223+
/// > is *possible* that decoding as an `Int32` could overflow even if a ``format`` of
224+
/// > ``IntegerFormat/int32`` is specified.
225+
///
226+
/// - Parameters:
227+
/// - description: An optional description of what the integer should contain or represent; may
228+
/// use Markdown format.
229+
/// - nullable: If `true`, instructs the model that it may return `null` instead of an integer;
230+
/// defaults to `false`, enforcing that an integer is returned.
231+
/// - format: An optional modifier describing the expected format of the integer. Currently the
232+
/// formats ``IntegerFormat/int32`` and ``IntegerFormat/int64`` are supported; custom values
233+
/// may be specified using ``IntegerFormat/custom(_:)`` but may be ignored by the model.
144234
public static func integer(description: String? = nil, nullable: Bool = false,
145235
format: IntegerFormat? = nil) -> Schema {
146236
return self.init(

0 commit comments

Comments
 (0)