@@ -20,7 +20,16 @@ public abstract class StringFormat private constructor(internal val value: Strin
2020 public class Custom (value : String ) : StringFormat(value)
2121}
2222
23- /* * Represents a schema */
23+ /* *
24+ * Definition of a data type.
25+ *
26+ * These types can be objects, but also primitives and arrays. Represents a select subset of an
27+ * [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema).
28+ *
29+ * **Note:** while optional, including a the `description` field in your `Schema`s is strongly
30+ * encouraged. The more information the model has about what it's expected to generate, the better
31+ * the results.
32+ */
2433public class Schema
2534internal constructor (
2635 public val type: String ,
@@ -34,7 +43,12 @@ internal constructor(
3443) {
3544
3645 public companion object {
37- /* * Returns a schema for a boolean */
46+ /* *
47+ * Returns a [Schema] representing a boolean value.
48+ *
49+ * @param description An optional description of what the boolean should contain or represent.
50+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
51+ */
3852 @JvmStatic
3953 @JvmOverloads
4054 public fun boolean (description : String? = null, nullable : Boolean = false): Schema =
@@ -45,10 +59,14 @@ internal constructor(
4559 )
4660
4761 /* *
48- * Returns a schema for a 32-bit integer number
62+ * Returns a [Schema] for a 32-bit signed integer number.
4963 *
50- * @param description: The description of what the parameter should contain or represent
51- * @param nullable: Whether null is a valid value for this schema
64+ * **Important:** This [Schema] provides a hint to the model that it should generate a 32-bit
65+ * integer, but only guarantees that the value will be an integer. Therefore it's *possible*
66+ * that decoding it as an `Int` variable, `int` in Java, could overflow.
67+ *
68+ * @param description An optional description of what the integer should contain or represent.
69+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
5270 */
5371 @JvmStatic
5472 @JvmName(" numInt" )
@@ -62,10 +80,10 @@ internal constructor(
6280 )
6381
6482 /* *
65- * Returns a schema for a 64-bit integer number
83+ * Returns a [Schema] for a 64-bit signed integer number.
6684 *
67- * @param description: The description of what the parameter should contain or represent
68- * @param nullable: Whether null is a valid value for this schema
85+ * @param description An optional description of what the number should contain or represent.
86+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
6987 */
7088 @JvmStatic
7189 @JvmName(" numLong" )
@@ -78,10 +96,10 @@ internal constructor(
7896 )
7997
8098 /* *
81- * Returns a schema for a floating point number
99+ * Returns a [Schema] for a double-precision floating- point number.
82100 *
83- * @param description: The description of what the parameter should contain or represent
84- * @param nullable: Whether null is a valid value for this schema
101+ * @param description An optional description of what the number should contain or represent.
102+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
85103 */
86104 @JvmStatic
87105 @JvmName(" numDouble" )
@@ -90,10 +108,15 @@ internal constructor(
90108 Schema (description = description, nullable = nullable, type = " NUMBER" , format = " double" )
91109
92110 /* *
93- * Returns a schema for a floating point number
111+ * Returns a [Schema] for a single-precision floating-point number.
112+ *
113+ * **Important:** This [Schema] provides a hint to the model that it should generate a
114+ * single-precision floating-point number, but only guarantees that the value will be a number.
115+ * Therefore it's *possible* that decoding it as a `Float` variable, `float` in Java, could
116+ * overflow.
94117 *
95- * @param description: The description of what the parameter should contain or represent
96- * @param nullable: Whether null is a valid value for this schema
118+ * @param description An optional description of what the number should contain or represent.
119+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
97120 */
98121 @JvmStatic
99122 @JvmName(" numFloat" )
@@ -102,11 +125,11 @@ internal constructor(
102125 Schema (description = description, nullable = nullable, type = " NUMBER" , format = " float" )
103126
104127 /* *
105- * Returns a schema for a string
128+ * Returns a [Schema] for a string.
106129 *
107- * @param description: The description of what the parameter should contain or represent
108- * @param nullable: Whether null is a valid value for this schema
109- * @param format: The pattern that values need to adhere to
130+ * @param description An optional description of what the string should contain or represent.
131+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
132+ * @param format An optional pattern that values need to adhere to.
110133 */
111134 @JvmStatic
112135 @JvmName(" str" )
@@ -124,11 +147,24 @@ internal constructor(
124147 )
125148
126149 /* *
127- * Returns a schema for a complex object. In a function, it will be returned as a [JSONObject].
150+ * Returns a [Schema] for a complex data type.
151+ *
152+ * This schema instructs the model to produce data of type object, which has keys of type
153+ * `String` and values of type [Schema].
128154 *
129- * @param properties: The map of the object's fields to their schema
130- * @param description: The description of what the parameter should contain or represent
131- * @param nullable: Whether null is a valid value for this schema
155+ * **Example:** A `City` could be represented with the following object `Schema`.
156+ * ```
157+ * Schema.obj(mapOf(
158+ * "name" to Schema.string(),
159+ * "population" to Schema.integer()
160+ * ))
161+ * ```
162+ *
163+ * @param properties The map of the object's property names to their [Schema]s. by the model.
164+ * These names must correspond to the keys provided in the `properties` map. By default it's
165+ * empty, signaling the model that all properties are to be included.
166+ * @param description An optional description of what the object represents.
167+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
132168 */
133169 @JvmStatic
134170 @JvmOverloads
@@ -153,11 +189,11 @@ internal constructor(
153189 }
154190
155191 /* *
156- * Returns a schema for an array.
192+ * Returns a [Schema] for an array.
157193 *
158- * @param items: The schema of the elements of this array
159- * @param description: The description of what the parameter should contain or represent
160- * @param nullable: Whether null is a valid value for this schema
194+ * @param item The [Schema] of the elements of stored in the array.
195+ * @param description An optional description of what the array represent.
196+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
161197 */
162198 @JvmStatic
163199 @JvmOverloads
@@ -174,11 +210,17 @@ internal constructor(
174210 )
175211
176212 /* *
177- * Returns a schema for an enumeration
213+ * Returns a [Schema] for an enumeration.
214+ *
215+ * For example, the cardinal directions can be represented as:
216+ *
217+ * ```
218+ * Schema.enumeration(listOf("north", "east", "south", "west"), "Cardinal directions")
219+ * ```
178220 *
179- * @param values: The list of valid values for this enumeration
180- * @param description: The description of what the parameter should contain or represent
181- * @param nullable: Whether null is a valid value for this schema
221+ * @param values The list of valid values for this enumeration
222+ * @param description The description of what the parameter should contain or represent
223+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
182224 */
183225 @JvmStatic
184226 @JvmOverloads
0 commit comments