@@ -20,7 +20,16 @@ public abstract class StringFormat private constructor(internal val value: Strin
20
20
public class Custom (value : String ) : StringFormat(value)
21
21
}
22
22
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 `description` field in your `Schema` is strongly
30
+ * encouraged. The more information the model has about what it's expected to generate, the better
31
+ * the results.
32
+ */
24
33
public class Schema
25
34
internal constructor (
26
35
public val type: String ,
@@ -34,7 +43,12 @@ internal constructor(
34
43
) {
35
44
36
45
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
+ */
38
52
@JvmStatic
39
53
@JvmOverloads
40
54
public fun boolean (description : String? = null, nullable : Boolean = false): Schema =
@@ -45,10 +59,14 @@ internal constructor(
45
59
)
46
60
47
61
/* *
48
- * Returns a schema for a 32-bit integer number
62
+ * Returns a [Schema] for a 32-bit signed integer number.
49
63
*
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 (or `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`.
52
70
*/
53
71
@JvmStatic
54
72
@JvmName(" numInt" )
@@ -62,10 +80,10 @@ internal constructor(
62
80
)
63
81
64
82
/* *
65
- * Returns a schema for a 64-bit integer number
83
+ * Returns a [Schema] for a 64-bit signed integer number.
66
84
*
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`.
69
87
*/
70
88
@JvmStatic
71
89
@JvmName(" numLong" )
@@ -78,10 +96,10 @@ internal constructor(
78
96
)
79
97
80
98
/* *
81
- * Returns a schema for a floating point number
99
+ * Returns a [Schema] for a double-precision floating- point number.
82
100
*
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`.
85
103
*/
86
104
@JvmStatic
87
105
@JvmName(" numDouble" )
@@ -90,10 +108,15 @@ internal constructor(
90
108
Schema (description = description, nullable = nullable, type = " NUMBER" , format = " double" )
91
109
92
110
/* *
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 (or `float` in Java) could
116
+ * overflow.
94
117
*
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`.
97
120
*/
98
121
@JvmStatic
99
122
@JvmName(" numFloat" )
@@ -102,11 +125,11 @@ internal constructor(
102
125
Schema (description = description, nullable = nullable, type = " NUMBER" , format = " float" )
103
126
104
127
/* *
105
- * Returns a schema for a string
128
+ * Returns a [Schema] for a string.
106
129
*
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.
110
133
*/
111
134
@JvmStatic
112
135
@JvmName(" str" )
@@ -124,11 +147,25 @@ internal constructor(
124
147
)
125
148
126
149
/* *
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].
128
154
*
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.
164
+ * @param optionalProperties The list of optional properties. They must correspond to the keys
165
+ * provided in the `properties` map. By default it's empty, signaling the model that all
166
+ * properties are to be included.
167
+ * @param description An optional description of what the object represents.
168
+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
132
169
*/
133
170
@JvmStatic
134
171
@JvmOverloads
@@ -153,11 +190,11 @@ internal constructor(
153
190
}
154
191
155
192
/* *
156
- * Returns a schema for an array.
193
+ * Returns a [Schema] for an array.
157
194
*
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
195
+ * @param items The [Schema] of the elements stored in the array.
196
+ * @param description An optional description of what the array represents.
197
+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
161
198
*/
162
199
@JvmStatic
163
200
@JvmOverloads
@@ -174,11 +211,17 @@ internal constructor(
174
211
)
175
212
176
213
/* *
177
- * Returns a schema for an enumeration
214
+ * Returns a [Schema] for an enumeration.
215
+ *
216
+ * For example, the cardinal directions can be represented as:
217
+ *
218
+ * ```
219
+ * Schema.enumeration(listOf("north", "east", "south", "west"), "Cardinal directions")
220
+ * ```
178
221
*
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
222
+ * @param values The list of valid values for this enumeration
223
+ * @param description The description of what the parameter should contain or represent
224
+ * @param nullable Indicates whether the value can be `null`. Defaults to `false`.
182
225
*/
183
226
@JvmStatic
184
227
@JvmOverloads
0 commit comments