Schema.Companion

public static class Schema.Companion


Summary

Public methods

static final @NonNull Schema
array(@NonNull Schema items, String description, boolean nullable)

Returns a Schema for an array.

static final @NonNull Schema
boolean(String description, boolean nullable)

Returns a Schema representing a boolean value.

static final @NonNull Schema
enumeration(
    @NonNull List<@NonNull String> values,
    String description,
    boolean nullable
)

Returns a Schema for an enumeration.

static final @NonNull Schema
numDouble(String description, boolean nullable)

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

static final @NonNull Schema
numFloat(String description, boolean nullable)

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

static final @NonNull Schema
numInt(String description, boolean nullable)

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

static final @NonNull Schema
numLong(String description, boolean nullable)

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

static final @NonNull Schema
obj(
    @NonNull Map<@NonNull String, @NonNull Schema> properties,
    @NonNull List<@NonNull String> optionalProperties,
    String description,
    boolean nullable
)

Returns a Schema for a complex data type.

static final @NonNull Schema
str(String description, boolean nullable, StringFormat format)

Returns a Schema for a string.

Public methods

array

public static final @NonNull Schema array(@NonNull Schema items, String description, boolean nullable)

Returns a Schema for an array.

Parameters
@NonNull Schema items

The Schema of the elements stored in the array.

String description

An optional description of what the array represents.

boolean nullable

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

boolean

public static final @NonNull Schema boolean(String description, boolean nullable)

Returns a Schema representing a boolean value.

Parameters
String description

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

boolean nullable

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

enumeration

public static final @NonNull Schema enumeration(
    @NonNull List<@NonNull String> values,
    String description,
    boolean nullable
)

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
@NonNull List<@NonNull String> values

The list of valid values for this enumeration

String description

The description of what the parameter should contain or represent

boolean nullable

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

numDouble

public static final @NonNull Schema numDouble(String description, boolean nullable)

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

Parameters
String description

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

boolean nullable

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

numFloat

public static final @NonNull Schema numFloat(String description, boolean nullable)

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
String description

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

boolean nullable

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

numInt

public static final @NonNull Schema numInt(String description, boolean nullable)

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
String description

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

boolean nullable

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

numLong

public static final @NonNull Schema numLong(String description, boolean nullable)

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

Parameters
String description

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

boolean nullable

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

obj

public static final @NonNull Schema obj(
    @NonNull Map<@NonNull String, @NonNull Schema> properties,
    @NonNull List<@NonNull String> optionalProperties,
    String description,
    boolean nullable
)

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
@NonNull Map<@NonNull String, @NonNull Schema> properties

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

@NonNull List<@NonNull String> optionalProperties

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.

String description

An optional description of what the object represents.

boolean nullable

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

str

public static final @NonNull Schema str(String description, boolean nullable, StringFormat format)

Returns a Schema for a string.

Parameters
String description

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

boolean nullable

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

StringFormat format

An optional pattern that values need to adhere to.