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
array(items: Schema, description: String?, nullable: Boolean)

Returns a Schema for an array.

Schema
boolean(description: String?, nullable: Boolean)

Returns a Schema representing a boolean value.

Schema
double(description: String?, nullable: Boolean)

Returns a Schema for a double-precision floating-point number.

Schema
enumeration(values: List<String>, description: String?, nullable: Boolean)

Returns a Schema for an enumeration.

Schema
float(description: String?, nullable: Boolean)

Returns a Schema for a single-precision floating-point number.

Schema
integer(description: String?, nullable: Boolean)

Returns a Schema for a 32-bit signed integer number.

Schema
long(description: String?, nullable: Boolean)

Returns a Schema for a 64-bit signed integer number.

Schema
obj(
    properties: Map<StringSchema>,
    optionalProperties: List<String>,
    description: String?,
    nullable: Boolean
)

Returns a Schema for a complex data type.

Schema
string(description: String?, nullable: Boolean, format: StringFormat?)

Returns a Schema for a string.

Public companion functions

array

fun array(items: Schema, description: String? = null, nullable: Boolean = false): Schema

Returns a Schema for an array.

Parameters
items: Schema

The Schema of the elements stored in the array.

description: String? = null

An optional description of what the array represents.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

boolean

fun boolean(description: String? = null, nullable: Boolean = false): Schema

Returns a Schema representing a boolean value.

Parameters
description: String? = null

An optional description of what the boolean should contain or represent.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

double

fun double(description: String? = null, nullable: Boolean = false): Schema

Returns a Schema for a double-precision floating-point number.

Parameters
description: String? = null

An optional description of what the number should contain or represent.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

enumeration

fun enumeration(
    values: List<String>,
    description: String? = null,
    nullable: Boolean = false
): 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")
Parameters
values: List<String>

The list of valid values for this enumeration

description: String? = null

The description of what the parameter should contain or represent

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

float

fun float(description: String? = null, nullable: Boolean = false): 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.

Parameters
description: String? = null

An optional description of what the number should contain or represent.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

integer

fun integer(description: String? = null, nullable: Boolean = false): 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.

Parameters
description: String? = null

An optional description of what the integer should contain or represent.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

long

fun long(description: String? = null, nullable: Boolean = false): Schema

Returns a Schema for a 64-bit signed integer number.

Parameters
description: String? = null

An optional description of what the number should contain or represent.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

obj

fun obj(
    properties: Map<StringSchema>,
    optionalProperties: List<String> = emptyList(),
    description: String? = null,
    nullable: Boolean = false
): 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<StringSchema>

The map of the object's property names to their Schemas.

optionalProperties: List<String> = emptyList()

The list of optional properties. They must correspond to the keys provided in the properties map. By default it's empty, signaling the model that all properties are to be included.

description: String? = null

An optional description of what the object represents.

nullable: Boolean = false

Indicates whether the value can be null. Defaults to false.

string

fun string(
    description: String? = null,
    nullable: Boolean = false,
    format: StringFormat? = 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 null. Defaults to false.

format: StringFormat? = null

An optional pattern that values need to adhere to.

Public properties

description

val descriptionString?

enum

val enumList<String>?

format

val formatString?

items

val itemsSchema?

nullable

val nullableBoolean?

properties

val propertiesMap<StringSchema>?

required

val requiredList<String>?

type

val typeString