@@ -34,7 +34,7 @@ public abstract class StringFormat private constructor(internal val value: Strin
3434 */
3535public class Schema
3636internal constructor (
37- public val type: String? = null ,
37+ public val type: String ,
3838 public val description: String? = null ,
3939 public val format: String? = null ,
4040 public val nullable: Boolean? = null ,
@@ -47,7 +47,7 @@ internal constructor(
4747 public val maxItems: Int? = null ,
4848 public val minimum: Double? = null ,
4949 public val maximum: Double? = null ,
50- public val anyOf: List <Schema >? = null
50+ public val anyOf: List <Schema >? = null ,
5151) {
5252
5353 public companion object {
@@ -62,7 +62,7 @@ internal constructor(
6262 public fun boolean (
6363 description : String? = null,
6464 nullable : Boolean = false,
65- title : String? = null
65+ title : String? = null,
6666 ): Schema =
6767 Schema (description = description, nullable = nullable, type = " BOOLEAN" , title = title)
6868
@@ -84,7 +84,7 @@ internal constructor(
8484 nullable : Boolean = false,
8585 title : String? = null,
8686 minimum : Double? = null,
87- maximum : Double? = null
87+ maximum : Double? = null,
8888 ): Schema =
8989 Schema (
9090 description = description,
@@ -110,7 +110,7 @@ internal constructor(
110110 nullable : Boolean = false,
111111 title : String? = null,
112112 minimum : Double? = null,
113- maximum : Double? = null
113+ maximum : Double? = null,
114114 ): Schema =
115115 Schema (
116116 description = description,
@@ -135,7 +135,7 @@ internal constructor(
135135 nullable : Boolean = false,
136136 title : String? = null,
137137 minimum : Double? = null,
138- maximum : Double? = null
138+ maximum : Double? = null,
139139 ): Schema =
140140 Schema (
141141 description = description,
@@ -165,7 +165,7 @@ internal constructor(
165165 nullable : Boolean = false,
166166 title : String? = null,
167167 minimum : Double? = null,
168- maximum : Double? = null
168+ maximum : Double? = null,
169169 ): Schema =
170170 Schema (
171171 description = description,
@@ -198,7 +198,7 @@ internal constructor(
198198 format = format?.value,
199199 nullable = nullable,
200200 type = " STRING" ,
201- title = title
201+ title = title,
202202 )
203203
204204 /* *
@@ -208,6 +208,7 @@ internal constructor(
208208 * `String` and values of type [Schema].
209209 *
210210 * **Example:** A `city` could be represented with the following object `Schema`.
211+ *
211212 * ```
212213 * Schema.obj(mapOf(
213214 * "name" to Schema.string(),
@@ -229,7 +230,7 @@ internal constructor(
229230 optionalProperties : List <String > = emptyList(),
230231 description : String? = null,
231232 nullable : Boolean = false,
232- title : String? = null
233+ title : String? = null,
233234 ): Schema {
234235 if (! properties.keys.containsAll(optionalProperties)) {
235236 throw IllegalArgumentException (
@@ -242,7 +243,7 @@ internal constructor(
242243 properties = properties,
243244 required = properties.keys.minus(optionalProperties.toSet()).toList(),
244245 type = " OBJECT" ,
245- title = title
246+ title = title,
246247 )
247248 }
248249
@@ -261,7 +262,7 @@ internal constructor(
261262 nullable : Boolean = false,
262263 title : String? = null,
263264 minItems : Int? = null,
264- maxItems : Int? = null
265+ maxItems : Int? = null,
265266 ): Schema =
266267 Schema (
267268 description = description,
@@ -270,14 +271,13 @@ internal constructor(
270271 type = " ARRAY" ,
271272 title = title,
272273 minItems = minItems,
273- maxItems = maxItems
274+ maxItems = maxItems,
274275 )
275276
276277 /* *
277278 * Returns a [Schema] for an enumeration.
278279 *
279280 * For example, the cardinal directions can be represented as:
280- *
281281 * ```
282282 * Schema.enumeration(listOf("north", "east", "south", "west"), "Cardinal directions")
283283 * ```
@@ -300,7 +300,7 @@ internal constructor(
300300 nullable = nullable,
301301 enum = values,
302302 type = " STRING" ,
303- title = title
303+ title = title,
304304 )
305305
306306 /* *
@@ -310,23 +310,29 @@ internal constructor(
310310 * Example: A field that can hold either a simple userID or a more detailed user object.
311311 *
312312 * Schema.anyOf( listOf( Schema.integer(description = "User ID"), Schema.obj(mapOf(
313+ *
313314 * ```
314315 * "userID" to Schema.integer(description = "User ID"),
315316 * "username" to Schema.string(description = "Username")
316317 * ```
318+ *
317319 * )) )
318320 *
319321 * @param schemas The list of valid schemas which could be here
320322 */
321323 @JvmStatic
322- public fun anyOf (
323- schemas : List <Schema >,
324- ): Schema = Schema (anyOf = schemas)
324+ public fun anyOf (schemas : List <Schema >): Schema = Schema (type = " anyOf" , anyOf = schemas)
325325 }
326326
327- internal fun toInternal (): Internal =
328- Internal (
329- type,
327+ internal fun toInternal (): Internal {
328+ val cleanedType =
329+ if (type == " anyOf" ) {
330+ null
331+ } else {
332+ type
333+ }
334+ return Internal (
335+ cleanedType,
330336 description,
331337 format,
332338 nullable,
@@ -341,6 +347,8 @@ internal constructor(
341347 maximum,
342348 anyOf?.map { it.toInternal() },
343349 )
350+ }
351+
344352 @Serializable
345353 internal data class Internal (
346354 val type : String? = null ,
@@ -356,6 +364,6 @@ internal constructor(
356364 val maxItems : Int? = null ,
357365 val minimum : Double? = null ,
358366 val maximum : Double? = null ,
359- val anyOf : List <Internal >? = null
367+ val anyOf : List <Internal >? = null ,
360368 )
361369}
0 commit comments