AppFunctionOneOfTypeMetadata


class AppFunctionOneOfTypeMetadata : AppFunctionDataTypeMetadata


Defines the schema for a data type that can be one of several possible types, representing a form of polymorphism or a sealed hierarchy.

An object of this type must match exactly one of the schemas defined in the matchOneOf list. This is useful for modeling sealed classes or interfaces where an object can be one of a limited set of subtypes. This implies a hierarchical relationship between the parent type (represented by this OneOfTypeMetadata) and its possible concrete implementations in matchOneOf.

For example, consider the following sealed interface and its implementations:

package com.example.myapp

sealed
interface Animal {
val name: String
}

data class Dog(
override val name: String,
val breed: String,
)
: Animal

data
class Cat(
override val name: String,
val livesLeft: Int,
)
: Animal

The following AppFunctionOneOfTypeMetadata can be used to define a data type that matches any object implementing the Animal interface (i.e., either a Dog or a Cat).

val animalType = AppFunctionOneOfTypeMetadata(
qualifiedName = "com.example.myapp.Animal",
matchOneOf = listOf(
AppFunctionObjectTypeMetadata(
qualifiedName = "com.example.myapp.Dog",
properties = mapOf(
"name" to AppFunctionStringTypeMetadata(...),
"breed" to AppFunctionStringTypeMetadata(...),
),
required = listOf("name", "breed"),
isNullable = false,
),
AppFunctionObjectTypeMetadata(
qualifiedName = "com.example.myapp.Cat",
properties = mapOf(
"name" to AppFunctionStringTypeMetadata(...),
"livesLeft" to AppFunctionIntTypeMetadata(...),
),
required = listOf("name", "livesLeft"),
isNullable = false,
),
),
isNullable = false,
)

This data type can be used to define the schema of an input or output type.

Summary

Public constructors

AppFunctionOneOfTypeMetadata(
    matchOneOf: List<AppFunctionDataTypeMetadata>,
    qualifiedName: String,
    isNullable: Boolean,
    description: String
)

Public functions

open operator Boolean
equals(other: Any?)
open Int
open String

Public properties

List<AppFunctionDataTypeMetadata>

The list of possible data types that an object can match.

String

The parent object's qualified name if available.

Inherited properties

From androidx.appfunctions.metadata.AppFunctionDataTypeMetadata
String

A description of the data type and its intended use.

Boolean

Whether the data type is nullable.

Public constructors

AppFunctionOneOfTypeMetadata

AppFunctionOneOfTypeMetadata(
    matchOneOf: List<AppFunctionDataTypeMetadata>,
    qualifiedName: String,
    isNullable: Boolean,
    description: String = ""
)

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

matchOneOf

Added in 1.0.0-alpha06
val matchOneOfList<AppFunctionDataTypeMetadata>

The list of possible data types that an object can match.

qualifiedName

Added in 1.0.0-alpha06
val qualifiedNameString

The parent object's qualified name if available. For example, "com.example.myapp.Animal".

Use this value to set androidx.appfunctions.AppFunctionData.qualifiedName when trying to build the parameters for androidx.appfunctions.ExecuteAppFunctionRequest.