Package io.github.glaforge.gemini.schema
Class ObjectSchema
java.lang.Object
io.github.glaforge.gemini.schema.Schema
io.github.glaforge.gemini.schema.ObjectSchema
Schema for Object types.
Example usage:
obj()
.str("name")
.integer("age");
Note on convenience methods:
Methods like str(name), obj(name), etc., add a property to the current object
and return the current object schema to allow chaining siblings.
For example:
obj()
.obj("first") // Adds "first" property
.obj("second"); // Adds "second" property (sibling of "first")
Creates: { "first": {}, "second": {} }
To create nested objects, use prop(name, schema):
obj()
.prop("parent", obj()
.str("child"));
-
Field Summary
Fields inherited from class io.github.glaforge.gemini.schema.Schema
description, nullable, title, type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddProps(boolean allowed) Allow or disallow additional properties.Define the schema for additional properties.Add an array property.Add an array property with specified item schema.Add a boolean property.Add an integer property.Add an integer property with min and max constraints.Add an integer property with allowed enum values.Add a number property.Add a number property with min and max constraints.Add a number property with allowed enum values.Add an object property.Add a property to this object schema.Specify required properties.Helper to add a required property in one go.Add a string property.str(String name, StringSchema.Format format) Add a string property with a specific format.Add a string property with allowed enum values.toMap()Convert this Schema object into a Map suitable for JSON serialization.
-
Constructor Details
-
ObjectSchema
public ObjectSchema()Initializes a new object schema.
-
-
Method Details
-
prop
Add a property to this object schema.- Parameters:
name- The name of the property.schema- The schema for the property.- Returns:
- The ObjectSchema instance.
-
req
Specify required properties.- Parameters:
names- The names of the required properties.- Returns:
- The ObjectSchema instance.
-
reqProp
Helper to add a required property in one go.- Parameters:
name- The name of the property.schema- The schema for the property.- Returns:
- The ObjectSchema instance.
-
bool
Add a boolean property.- Parameters:
name- The name of the property.- Returns:
- The ObjectSchema instance.
-
str
Add a string property.- Parameters:
name- The name of the property.- Returns:
- The ObjectSchema instance.
-
str
Add a string property with a specific format.- Parameters:
name- The name of the property.format- The format of the string.- Returns:
- The ObjectSchema instance.
-
str
Add a string property with allowed enum values.- Parameters:
name- The name of the property.enumValues- The allowed values.- Returns:
- The ObjectSchema instance.
-
num
Add a number property.- Parameters:
name- The name of the property.- Returns:
- The ObjectSchema instance.
-
num
Add a number property with min and max constraints.- Parameters:
name- The name of the property.min- The minimum value.max- The maximum value.- Returns:
- The ObjectSchema instance.
-
num
Add a number property with allowed enum values.- Parameters:
name- The name of the property.enumValues- The allowed values.- Returns:
- The ObjectSchema instance.
-
integer
Add an integer property.- Parameters:
name- The name of the property.- Returns:
- The ObjectSchema instance.
-
integer
Add an integer property with min and max constraints.- Parameters:
name- The name of the property.min- The minimum value.max- The maximum value.- Returns:
- The ObjectSchema instance.
-
integer
Add an integer property with allowed enum values.- Parameters:
name- The name of the property.enumValues- The allowed values.- Returns:
- The ObjectSchema instance.
-
arr
Add an array property.- Parameters:
name- The name of the property.- Returns:
- The ObjectSchema instance.
-
arr
Add an array property with specified item schema.- Parameters:
name- The name of the property.itemSchema- The schema for the items in the array.- Returns:
- The ObjectSchema instance.
-
obj
Add an object property.- Parameters:
name- The name of the property.- Returns:
- The ObjectSchema instance.
-
addProps
Allow or disallow additional properties.- Parameters:
allowed- Whether additional properties are allowed.- Returns:
- The ObjectSchema instance.
-
addProps
Define the schema for additional properties.- Parameters:
schema- The schema for additional properties.- Returns:
- The ObjectSchema instance.
-
toMap
Description copied from class:SchemaConvert this Schema object into a Map suitable for JSON serialization.
-