@@ -20,13 +20,13 @@ import com.google.firebase.ai.annotation.ListSchemaDetails
20
20
import com.google.firebase.ai.annotation.NumSchemaDetails
21
21
import com.google.firebase.ai.annotation.SchemaDetails
22
22
import com.google.firebase.ai.annotation.StringSchemaDetails
23
- import kotlinx.serialization.SerialName
24
- import kotlinx.serialization.Serializable
25
23
import kotlin.reflect.KClass
26
24
import kotlin.reflect.KProperty1
27
25
import kotlin.reflect.full.findAnnotations
28
26
import kotlin.reflect.full.memberProperties
29
27
import kotlin.reflect.jvm.jvmErasure
28
+ import kotlinx.serialization.SerialName
29
+ import kotlinx.serialization.Serializable
30
30
31
31
public abstract class StringFormat private constructor(internal val value : String ) {
32
32
public class Custom (value : String ) : StringFormat(value)
@@ -366,11 +366,7 @@ internal constructor(
366
366
)
367
367
}
368
368
Boolean ::class -> {
369
- boolean(
370
- schemaDetails?.description,
371
- nullable,
372
- schemaDetails?.title
373
- )
369
+ boolean(schemaDetails?.description, nullable, schemaDetails?.title)
374
370
}
375
371
Float ::class -> {
376
372
float(
@@ -398,12 +394,11 @@ internal constructor(
398
394
schemaDetails?.title
399
395
)
400
396
}
401
-
402
397
List ::class -> {
403
398
if (listSchemaDetails == null ) {
404
399
throw IllegalStateException (
405
400
" ${clazz.simpleName} $${propertyName} must include " +
406
- " @ListSchemaDetails to use automatic schema generation."
401
+ " @ListSchemaDetails to use automatic schema generation."
407
402
)
408
403
}
409
404
array(
@@ -418,38 +413,44 @@ internal constructor(
418
413
else -> {
419
414
val isSerializable = clazz.findAnnotations(Serializable ::class ).isNotEmpty()
420
415
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
+ )
423
419
}
424
420
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
+ )
427
424
}
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 (
445
442
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
+ )
450
452
)
451
- )
452
- }
453
+ }
453
454
obj(
454
455
properties,
455
456
emptyList(),
@@ -462,8 +463,6 @@ internal constructor(
462
463
}
463
464
}
464
465
465
-
466
-
467
466
internal fun toInternal (): Internal {
468
467
val cleanedType =
469
468
if (type == " ANYOF" ) {
0 commit comments