Schema
class Schema
Definition of a data type.
These types can be objects, but also primitives and arrays. Represents a select subset of an OpenAPI 3.0 schema object.
Note: While optional, including a description field in your Schema is strongly encouraged. The more information the model has about what it's expected to generate, the better the results.
Summary
Public companion functions |
|
|---|---|
Schema |
Returns a |
Schema |
array(Returns a |
Schema |
Returns a |
Schema |
double(Returns a |
Schema |
Returns a |
Schema |
Returns a |
Schema |
integer(Returns a |
Schema |
Returns a |
Schema |
obj(Returns a |
Schema |
string(Returns a |
Public properties |
|
|---|---|
List<Schema>? |
|
String? |
|
List<String>? |
|
String? |
|
Schema? |
|
Int? |
|
Double? |
|
Int? |
|
Double? |
|
Boolean? |
|
Map<String, Schema>? |
|
List<String>? |
|
String? |
|
String |
Public companion functions
anyOf
fun anyOf(schemas: List<Schema>): Schema
Returns a Schema representing a value that must conform to any (one of) the provided sub-schema.
Example: A field that can hold either a simple userID or a more detailed user object.
Schema.anyOf( listOf( Schema.integer(description = "User ID"), Schema.obj( mapOf(
"userID" to Schema.integer(description = "User ID"),
"username" to Schema.string(description = "Username")
)))
array
fun array(
items: Schema,
description: String? = null,
nullable: Boolean = false,
title: String? = null,
minItems: Int? = null,
maxItems: Int? = null
): Schema
Returns a Schema for an array.
boolean
fun boolean(description: String? = null, nullable: Boolean = false, title: String? = null): Schema
Returns a Schema representing a boolean value.
double
fun double(
description: String? = null,
nullable: Boolean = false,
title: String? = null,
minimum: Double? = null,
maximum: Double? = null
): Schema
Returns a Schema for a double-precision floating-point number.
enumeration
fun enumeration(
values: List<String>,
description: String? = null,
nullable: Boolean = false,
title: String? = null
): Schema
Returns a Schema for an enumeration.
For example, the cardinal directions can be represented as:
Schema.enumeration(listOf("north", "east", "south", "west"), "Cardinal directions")
float
fun float(
description: String? = null,
nullable: Boolean = false,
title: String? = null,
minimum: Double? = null,
maximum: Double? = null
): Schema
Returns a Schema for a single-precision floating-point number.
Important: This Schema provides a hint to the model that it should generate a single-precision floating-point number, but only guarantees that the value will be a number. Therefore it's possible that decoding it as a Float variable (or float in Java) could overflow.
integer
fun integer(
description: String? = null,
nullable: Boolean = false,
title: String? = null,
minimum: Double? = null,
maximum: Double? = null
): Schema
Returns a Schema for a 32-bit signed integer number.
Important: This Schema provides a hint to the model that it should generate a 32-bit integer, but only guarantees that the value will be an integer. Therefore it's possible that decoding it as an Int variable (or int in Java) could overflow.
long
fun long(
description: String? = null,
nullable: Boolean = false,
title: String? = null,
minimum: Double? = null,
maximum: Double? = null
): Schema
Returns a Schema for a 64-bit signed integer number.
obj
fun obj(
properties: Map<String, Schema>,
optionalProperties: List<String> = emptyList(),
description: String? = null,
nullable: Boolean = false,
title: String? = null
): Schema
Returns a Schema for a complex data type.
This schema instructs the model to produce data of type object, which has keys of type String and values of type Schema.
Example: A city could be represented with the following object Schema.
Schema.obj(mapOf(
"name" to Schema.string(),
"population" to Schema.integer()
))
| Parameters | |
|---|---|
properties: Map<String, Schema> |
The map of the object's property names to their |
optionalProperties: List<String> = emptyList() |
The list of optional properties. They must correspond to the keys provided in the |
description: String? = null |
An optional description of what the object represents. |
nullable: Boolean = false |
Indicates whether the value can be |
string
fun string(
description: String? = null,
nullable: Boolean = false,
format: StringFormat? = null,
title: String? = null
): Schema
Returns a Schema for a string.
| Parameters | |
|---|---|
description: String? = null |
An optional description of what the string should contain or represent. |
nullable: Boolean = false |
Indicates whether the value can be |
format: StringFormat? = null |
An optional pattern that values need to adhere to. |