Skip to content

Commit e105a8c

Browse files
author
David Motsonashvili
committed
make type non-nullable
1 parent 357b4a5 commit e105a8c

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

firebase-ai/api.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ package com.google.firebase.ai.type {
793793
method public java.util.Map<java.lang.String,com.google.firebase.ai.type.Schema>? getProperties();
794794
method public java.util.List<java.lang.String>? getRequired();
795795
method public String? getTitle();
796-
method public String? getType();
796+
method public String getType();
797797
method public static com.google.firebase.ai.type.Schema numDouble();
798798
method public static com.google.firebase.ai.type.Schema numDouble(String? description = null);
799799
method public static com.google.firebase.ai.type.Schema numDouble(String? description = null, boolean nullable = false);
@@ -841,7 +841,7 @@ package com.google.firebase.ai.type {
841841
property public final java.util.Map<java.lang.String,com.google.firebase.ai.type.Schema>? properties;
842842
property public final java.util.List<java.lang.String>? required;
843843
property public final String? title;
844-
property public final String? type;
844+
property public final String type;
845845
field public static final com.google.firebase.ai.type.Schema.Companion Companion;
846846
}
847847

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Schema.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class StringFormat private constructor(internal val value: Strin
3434
*/
3535
public class Schema
3636
internal constructor(
37-
public val type: String? = null,
37+
public val type: String,
3838
public val description: String? = null,
3939
public val format: String? = null,
4040
public val nullable: Boolean? = null,
@@ -47,7 +47,7 @@ internal constructor(
4747
public val maxItems: Int? = null,
4848
public val minimum: Double? = null,
4949
public val maximum: Double? = null,
50-
public val anyOf: List<Schema>? = null
50+
public val anyOf: List<Schema>? = null,
5151
) {
5252

5353
public companion object {
@@ -62,7 +62,7 @@ internal constructor(
6262
public fun boolean(
6363
description: String? = null,
6464
nullable: Boolean = false,
65-
title: String? = null
65+
title: String? = null,
6666
): Schema =
6767
Schema(description = description, nullable = nullable, type = "BOOLEAN", title = title)
6868

@@ -84,7 +84,7 @@ internal constructor(
8484
nullable: Boolean = false,
8585
title: String? = null,
8686
minimum: Double? = null,
87-
maximum: Double? = null
87+
maximum: Double? = null,
8888
): Schema =
8989
Schema(
9090
description = description,
@@ -110,7 +110,7 @@ internal constructor(
110110
nullable: Boolean = false,
111111
title: String? = null,
112112
minimum: Double? = null,
113-
maximum: Double? = null
113+
maximum: Double? = null,
114114
): Schema =
115115
Schema(
116116
description = description,
@@ -135,7 +135,7 @@ internal constructor(
135135
nullable: Boolean = false,
136136
title: String? = null,
137137
minimum: Double? = null,
138-
maximum: Double? = null
138+
maximum: Double? = null,
139139
): Schema =
140140
Schema(
141141
description = description,
@@ -165,7 +165,7 @@ internal constructor(
165165
nullable: Boolean = false,
166166
title: String? = null,
167167
minimum: Double? = null,
168-
maximum: Double? = null
168+
maximum: Double? = null,
169169
): Schema =
170170
Schema(
171171
description = description,
@@ -198,7 +198,7 @@ internal constructor(
198198
format = format?.value,
199199
nullable = nullable,
200200
type = "STRING",
201-
title = title
201+
title = title,
202202
)
203203

204204
/**
@@ -208,6 +208,7 @@ internal constructor(
208208
* `String` and values of type [Schema].
209209
*
210210
* **Example:** A `city` could be represented with the following object `Schema`.
211+
*
211212
* ```
212213
* Schema.obj(mapOf(
213214
* "name" to Schema.string(),
@@ -229,7 +230,7 @@ internal constructor(
229230
optionalProperties: List<String> = emptyList(),
230231
description: String? = null,
231232
nullable: Boolean = false,
232-
title: String? = null
233+
title: String? = null,
233234
): Schema {
234235
if (!properties.keys.containsAll(optionalProperties)) {
235236
throw IllegalArgumentException(
@@ -242,7 +243,7 @@ internal constructor(
242243
properties = properties,
243244
required = properties.keys.minus(optionalProperties.toSet()).toList(),
244245
type = "OBJECT",
245-
title = title
246+
title = title,
246247
)
247248
}
248249

@@ -261,7 +262,7 @@ internal constructor(
261262
nullable: Boolean = false,
262263
title: String? = null,
263264
minItems: Int? = null,
264-
maxItems: Int? = null
265+
maxItems: Int? = null,
265266
): Schema =
266267
Schema(
267268
description = description,
@@ -270,14 +271,13 @@ internal constructor(
270271
type = "ARRAY",
271272
title = title,
272273
minItems = minItems,
273-
maxItems = maxItems
274+
maxItems = maxItems,
274275
)
275276

276277
/**
277278
* Returns a [Schema] for an enumeration.
278279
*
279280
* For example, the cardinal directions can be represented as:
280-
*
281281
* ```
282282
* Schema.enumeration(listOf("north", "east", "south", "west"), "Cardinal directions")
283283
* ```
@@ -300,7 +300,7 @@ internal constructor(
300300
nullable = nullable,
301301
enum = values,
302302
type = "STRING",
303-
title = title
303+
title = title,
304304
)
305305

306306
/**
@@ -310,23 +310,29 @@ internal constructor(
310310
* Example: A field that can hold either a simple userID or a more detailed user object.
311311
*
312312
* Schema.anyOf( listOf( Schema.integer(description = "User ID"), Schema.obj(mapOf(
313+
*
313314
* ```
314315
* "userID" to Schema.integer(description = "User ID"),
315316
* "username" to Schema.string(description = "Username")
316317
* ```
318+
*
317319
* )) )
318320
*
319321
* @param schemas The list of valid schemas which could be here
320322
*/
321323
@JvmStatic
322-
public fun anyOf(
323-
schemas: List<Schema>,
324-
): Schema = Schema(anyOf = schemas)
324+
public fun anyOf(schemas: List<Schema>): Schema = Schema(type = "anyOf", anyOf = schemas)
325325
}
326326

327-
internal fun toInternal(): Internal =
328-
Internal(
329-
type,
327+
internal fun toInternal(): Internal {
328+
val cleanedType =
329+
if (type == "anyOf") {
330+
null
331+
} else {
332+
type
333+
}
334+
return Internal(
335+
cleanedType,
330336
description,
331337
format,
332338
nullable,
@@ -341,6 +347,8 @@ internal constructor(
341347
maximum,
342348
anyOf?.map { it.toInternal() },
343349
)
350+
}
351+
344352
@Serializable
345353
internal data class Internal(
346354
val type: String? = null,
@@ -356,6 +364,6 @@ internal constructor(
356364
val maxItems: Int? = null,
357365
val minimum: Double? = null,
358366
val maximum: Double? = null,
359-
val anyOf: List<Internal>? = null
367+
val anyOf: List<Internal>? = null,
360368
)
361369
}

0 commit comments

Comments
 (0)