README.md
1# AppFunction Metadata
2
3This document explains how the `AppFunctionMetadata` and related Kotlin classes are inspired by the
4OpenAPI specification, and highlights the similarities, deviations, and important design choices
5made in this implementation.
6
7## Overview
8
9The package defines a set of classes to represent metadata for AppFunctions. This metadata is
10designed to be similar in spirit to the OpenAPI specification, which is used to describe REST APIs.
11The goal here is to provide a structured and machine-readable way to define and understand the
12inputs, outputs, and other characteristics of functions within an application, much like OpenAPI
13does for web APIs.
14
15## Similarities to OpenAPI
16
17* **Operation Object (`AppFunctionMetadata`):** Just like an OpenAPI Operation Object describes
18 an API endpoint, `AppFunctionMetadata` describes an AppFunction. It contains essential
19 information needed to invoke and understand the function.
20* **Parameter Object (`AppFunctionParameterMetadata`):** This class directly corresponds to the
21 Parameter Object in OpenAPI. It defines the name, requirement status (`isRequired`), and data
22 type (`dataType`) of a function parameter, similar to how OpenAPI describes request parameters.
23* **Schema Object (`AppFunctionDataTypeMetadata` and subclasses):** `AppFunctionDataTypeMetadata`
24 and its subclasses (`AppFunctionPrimitiveTypeMetadata`, `AppFunctionObjectTypeMetadata`,
25 `AppFunctionArrayTypeMetadata`, `AppFunctionReferenceTypeMetadata`) are analogous to the Schema
26 Object in OpenAPI. They are used to define the data types of parameters and responses, including
27 primitive types, objects, arrays, and references to reusable schemas.
28* **Components Object (`AppFunctionComponentsMetadata`):** This class mirrors the Components
29 Object in OpenAPI. It provides a mechanism to define reusable data type schemas (`dataTypes`)
30 that can be referenced from different parts of the function definition.
31
32## Differences from OpenAPI
33
34While inspired by OpenAPI, this implementation also deviates in several ways, tailored for the
35specific needs of describing AppFunctions rather than web APIs:
36
37* **Focus on Function Metadata, Not API Endpoints:** OpenAPI is primarily designed to describe
38 RESTful APIs. This implementation is focused on describing the metadata of *functions* within an
39 application. Therefore, concepts specific to HTTP like paths, methods, request bodies, headers,
40 and multiple response codes are absent or simplified.
41* **Simplified Response Handling (`AppFunctionResponseMetadata`):** OpenAPI's `Responses Object`
42 is quite complex, allowing for multiple response codes, headers, and content types.
43 `AppFunctionResponseMetadata` is significantly simpler, primarily focusing on the `valueType`
44 (the schema of the return value). This simplification is because the function in Kotlin is more
45 controlled than a general web API, having a single primary successful response type.
46* **Schema Category and Version (`AppFunctionSchemaMetadata`) vs. Schema Object Naming:** In
47 OpenAPI, the term "Schema Object" refers to the definition of data structures (like objects,
48 arrays, primitive types). In `AppFunctionMetadata`, the class responsible for defining data
49 types is named `AppFunctionDataTypeMetadata`. The term "Schema" is instead used in
50 `AppFunctionSchemaMetadata` to represent a *predefined function schema*, identified by a
51 category, name, and version. This "AppFunction Schema" represents a higher-level concept of a
52 function's overall purpose and contract. For instance, we might predefine a schema for
53 "CreateNote," which specifies the function's required inputs and expected outputs.
54
55## Persistent format
56
57For each Metadata class, there is a corresponding internal "Document" class (e.g.,
58`AppFunctionParameterMetadataDocument`) that represents a persistent format of it. These "Document"
59classes are AppSearch documents. They are intended to be stored in the Android platform's AppSearch
60database, enabling applications with the necessary permissions to efficiently look up and discover
61available AppFunctions.
62
63**Important Note on Document Class Divergence:** Due to the underlying storage mechanism of
64AppSearch, the structure of the "Document" classes may diverge from their corresponding Metadata
65classes. For instance, AppSearch has limitations on the data types it can directly store, and
66complex structures like `Map<>` are not natively supported. As a result, Document classes might
67need to represent data in a flattened or transformed manner. You will notice that while Metadata
68classes may utilize `Map<>` (e.g., `AppFunctionObjectTypeMetadata.properties`,
69`AppFunctionComponentsMetadata.dataTypes`), the corresponding Document classes will likely use
70alternative representations suitable for AppSearch, such as lists of key-value pairs or other
71compatible structures.
72