Skip to content

Commit 2ccc84b

Browse files
author
David Motsonashvili
committed
fix formatting add api.txt and license
1 parent ce896d9 commit 2ccc84b

File tree

4 files changed

+117
-55
lines changed

4 files changed

+117
-55
lines changed

firebase-ai/api.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,38 @@ package com.google.firebase.ai {
8080

8181
}
8282

83+
package com.google.firebase.ai.annotation {
84+
85+
@kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.RUNTIME) @kotlin.annotation.Target(allowedTargets=kotlin.annotation.AnnotationTarget.PROPERTY) public @interface ListSchemaDetails {
86+
method public abstract kotlin.reflect.KClass<? extends java.lang.Object?> clazz();
87+
method public abstract int maxItems();
88+
method public abstract int minItems();
89+
property public abstract kotlin.reflect.KClass<? extends java.lang.Object?> clazz;
90+
property public abstract int maxItems;
91+
property public abstract int minItems;
92+
}
93+
94+
@kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.RUNTIME) @kotlin.annotation.Target(allowedTargets=kotlin.annotation.AnnotationTarget.PROPERTY) public @interface NumSchemaDetails {
95+
method public abstract double maximum();
96+
method public abstract double minimum();
97+
property public abstract double maximum;
98+
property public abstract double minimum;
99+
}
100+
101+
@kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.RUNTIME) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.CLASS, kotlin.annotation.AnnotationTarget.PROPERTY}) public @interface SchemaDetails {
102+
method public abstract String description();
103+
method public abstract String title();
104+
property public abstract String description;
105+
property public abstract String title;
106+
}
107+
108+
@kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.RUNTIME) @kotlin.annotation.Target(allowedTargets=kotlin.annotation.AnnotationTarget.PROPERTY) public @interface StringSchemaDetails {
109+
method public abstract String format();
110+
property public abstract String format;
111+
}
112+
113+
}
114+
83115
package com.google.firebase.ai.java {
84116

85117
public abstract class ChatFutures {
@@ -955,6 +987,7 @@ package com.google.firebase.ai.type {
955987
method public static com.google.firebase.ai.type.Schema enumeration(java.util.List<java.lang.String> values, String? description = null);
956988
method public static com.google.firebase.ai.type.Schema enumeration(java.util.List<java.lang.String> values, String? description = null, boolean nullable = false);
957989
method public static com.google.firebase.ai.type.Schema enumeration(java.util.List<java.lang.String> values, String? description = null, boolean nullable = false, String? title = null);
990+
method public static com.google.firebase.ai.type.Schema fromClass(kotlin.reflect.KClass<? extends java.lang.Object?> clazz, boolean nullable = false);
958991
method public java.util.List<com.google.firebase.ai.type.Schema>? getAnyOf();
959992
method public String? getDescription();
960993
method public java.util.List<java.lang.String>? getEnum();
@@ -1036,6 +1069,7 @@ package com.google.firebase.ai.type {
10361069
method public com.google.firebase.ai.type.Schema enumeration(java.util.List<java.lang.String> values, String? description = null);
10371070
method public com.google.firebase.ai.type.Schema enumeration(java.util.List<java.lang.String> values, String? description = null, boolean nullable = false);
10381071
method public com.google.firebase.ai.type.Schema enumeration(java.util.List<java.lang.String> values, String? description = null, boolean nullable = false, String? title = null);
1072+
method public com.google.firebase.ai.type.Schema fromClass(kotlin.reflect.KClass<? extends java.lang.Object?> clazz, boolean nullable = false);
10391073
method public com.google.firebase.ai.type.Schema numDouble();
10401074
method public com.google.firebase.ai.type.Schema numDouble(String? description = null);
10411075
method public com.google.firebase.ai.type.Schema numDouble(String? description = null, boolean nullable = false);

firebase-ai/src/main/kotlin/com/google/firebase/ai/annotation/SchemaDetails.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.google.firebase.ai.annotation
217

318
import kotlin.reflect.KClass
@@ -12,8 +27,12 @@ public annotation class NumSchemaDetails(val minimum: Double, val maximum: Doubl
1227

1328
@Retention(AnnotationRetention.RUNTIME)
1429
@Target(AnnotationTarget.PROPERTY)
15-
public annotation class ListSchemaDetails(val minItems: Int, val maxItems: Int, val clazz: KClass<*>)
30+
public annotation class ListSchemaDetails(
31+
val minItems: Int,
32+
val maxItems: Int,
33+
val clazz: KClass<*>
34+
)
1635

1736
@Retention(AnnotationRetention.RUNTIME)
1837
@Target(AnnotationTarget.PROPERTY)
19-
public annotation class StringSchemaDetails(val format: String)
38+
public annotation class StringSchemaDetails(val format: String)

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

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import com.google.firebase.ai.annotation.ListSchemaDetails
2020
import com.google.firebase.ai.annotation.NumSchemaDetails
2121
import com.google.firebase.ai.annotation.SchemaDetails
2222
import com.google.firebase.ai.annotation.StringSchemaDetails
23-
import kotlinx.serialization.SerialName
24-
import kotlinx.serialization.Serializable
2523
import kotlin.reflect.KClass
2624
import kotlin.reflect.KProperty1
2725
import kotlin.reflect.full.findAnnotations
2826
import kotlin.reflect.full.memberProperties
2927
import kotlin.reflect.jvm.jvmErasure
28+
import kotlinx.serialization.SerialName
29+
import kotlinx.serialization.Serializable
3030

3131
public abstract class StringFormat private constructor(internal val value: String) {
3232
public class Custom(value: String) : StringFormat(value)
@@ -366,11 +366,7 @@ internal constructor(
366366
)
367367
}
368368
Boolean::class -> {
369-
boolean(
370-
schemaDetails?.description,
371-
nullable,
372-
schemaDetails?.title
373-
)
369+
boolean(schemaDetails?.description, nullable, schemaDetails?.title)
374370
}
375371
Float::class -> {
376372
float(
@@ -398,12 +394,11 @@ internal constructor(
398394
schemaDetails?.title
399395
)
400396
}
401-
402397
List::class -> {
403398
if (listSchemaDetails == null) {
404399
throw IllegalStateException(
405400
"${clazz.simpleName}$${propertyName} must include " +
406-
"@ListSchemaDetails to use automatic schema generation."
401+
"@ListSchemaDetails to use automatic schema generation."
407402
)
408403
}
409404
array(
@@ -418,38 +413,44 @@ internal constructor(
418413
else -> {
419414
val isSerializable = clazz.findAnnotations(Serializable::class).isNotEmpty()
420415
if (!isSerializable) {
421-
throw IllegalStateException("${clazz.simpleName} must be @Serializable to use automatic " +
422-
"schema generation.")
416+
throw IllegalStateException(
417+
"${clazz.simpleName} must be @Serializable to use automatic " + "schema generation."
418+
)
423419
}
424420
if (!clazz.isData) {
425-
throw IllegalStateException("${clazz.simpleName} must be a data class to use automatic " +
426-
"schema generation.")
421+
throw IllegalStateException(
422+
"${clazz.simpleName} must be a data class to use automatic " + "schema generation."
423+
)
427424
}
428-
val classSchemaDetails = schemaDetails ?: clazz.findAnnotations(SchemaDetails::class).firstOrNull()
429-
?: throw IllegalStateException("${clazz.simpleName} must include @SchemaDetails to use " +
430-
"automatic schema generation.")
431-
val properties = clazz.memberProperties.associate { property: KProperty1<out Any, *> ->
432-
val propertyDetails = property.findAnnotations(SchemaDetails::class).firstOrNull()
433-
val stringDetails =
434-
property.findAnnotations(StringSchemaDetails::class).firstOrNull()
435-
val numDetails = property.findAnnotations(NumSchemaDetails::class).firstOrNull()
436-
val listDetails = property.findAnnotations(ListSchemaDetails::class).firstOrNull()
437-
val serialName = property.findAnnotations(SerialName::class).firstOrNull()
438-
val deepPropertyName = serialName?.value ?: property.name
439-
val propertyClass = property.returnType
440-
Pair(
441-
deepPropertyName,
442-
fromClassHelper(
443-
propertyClass.jvmErasure,
444-
propertyClass.isMarkedNullable,
425+
val classSchemaDetails =
426+
schemaDetails
427+
?: clazz.findAnnotations(SchemaDetails::class).firstOrNull()
428+
?: throw IllegalStateException(
429+
"${clazz.simpleName} must include @SchemaDetails to use " +
430+
"automatic schema generation."
431+
)
432+
val properties =
433+
clazz.memberProperties.associate { property: KProperty1<out Any, *> ->
434+
val propertyDetails = property.findAnnotations(SchemaDetails::class).firstOrNull()
435+
val stringDetails = property.findAnnotations(StringSchemaDetails::class).firstOrNull()
436+
val numDetails = property.findAnnotations(NumSchemaDetails::class).firstOrNull()
437+
val listDetails = property.findAnnotations(ListSchemaDetails::class).firstOrNull()
438+
val serialName = property.findAnnotations(SerialName::class).firstOrNull()
439+
val deepPropertyName = serialName?.value ?: property.name
440+
val propertyClass = property.returnType
441+
Pair(
445442
deepPropertyName,
446-
propertyDetails,
447-
numDetails,
448-
listDetails,
449-
stringDetails
443+
fromClassHelper(
444+
propertyClass.jvmErasure,
445+
propertyClass.isMarkedNullable,
446+
deepPropertyName,
447+
propertyDetails,
448+
numDetails,
449+
listDetails,
450+
stringDetails
451+
)
450452
)
451-
)
452-
}
453+
}
453454
obj(
454455
properties,
455456
emptyList(),
@@ -462,8 +463,6 @@ internal constructor(
462463
}
463464
}
464465

465-
466-
467466
internal fun toInternal(): Internal {
468467
val cleanedType =
469468
if (type == "ANYOF") {

firebase-ai/src/test/java/com/google/firebase/ai/SchemaGenerationTest.kt

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.google.firebase.ai
217

318
import com.google.firebase.ai.annotation.ListSchemaDetails
@@ -45,39 +60,36 @@ class SchemaGenerationTest {
4560
),
4661
"val8" to
4762
Schema.obj(
48-
mapOf("customSerialName" to Schema.array(Schema.string(), minItems = 0, maxItems = 500)),
63+
mapOf(
64+
"customSerialName" to Schema.array(Schema.string(), minItems = 0, maxItems = 500)
65+
),
4966
emptyList(),
5067
"A test field (8)",
5168
false,
5269
"var8",
5370
),
5471
),
5572
)
56-
assert(schema.toInternal() == generatedSchema.toInternal())
73+
assert(schema.toInternal() == generatedSchema.toInternal())
5774
}
5875

5976
@Serializable
6077
@SchemaDetails("A test class (1)", "TestClass1")
6178
data class TestClass1(
62-
@SchemaDetails("A test field (1)", "var1")
63-
val val1: Int,
79+
@SchemaDetails("A test field (1)", "var1") val val1: Int,
6480
@NumSchemaDetails(minimum = 20.0, maximum = 30.0)
6581
@SchemaDetails("A test field (2)", "var2")
6682
val val2: Long,
67-
@SchemaDetails("A test field (3)", "var3")
68-
val val3: Boolean,
69-
@SchemaDetails("A test field (4)", "var4")
70-
val val4: Float,
71-
@SchemaDetails("A test field (5)", "var5")
72-
val val5: Double,
83+
@SchemaDetails("A test field (3)", "var3") val val3: Boolean,
84+
@SchemaDetails("A test field (4)", "var4") val val4: Float,
85+
@SchemaDetails("A test field (5)", "var5") val val5: Double,
7386
@SchemaDetails("A test field (6)", "var6")
7487
@StringSchemaDetails("StringFormat")
7588
val val6: String,
7689
@SchemaDetails("A test field (7)", "var7")
7790
@ListSchemaDetails(0, 500, TestClass2::class)
7891
val val7: List<TestClass2>,
79-
@SchemaDetails("A test field (8)", "var8")
80-
val val8: TestClass3,
92+
@SchemaDetails("A test field (8)", "var8") val val8: TestClass3,
8193
)
8294

8395
@Serializable
@@ -87,8 +99,6 @@ class SchemaGenerationTest {
8799
@Serializable
88100
@SchemaDetails("A test class (3)", "TestClass3")
89101
data class TestClass3(
90-
@ListSchemaDetails(0, 500, String::class)
91-
@SerialName("customSerialName")
92-
val val1: List<String>
102+
@ListSchemaDetails(0, 500, String::class) @SerialName("customSerialName") val val1: List<String>
93103
)
94104
}

0 commit comments

Comments
 (0)