Class ElicitSchema
2026-07-28 SEP-2322), producing the
JsonMap consumed by ElicitRequest.setRequestedSchema(java.util.Map).
The elicitation restricted schema permits only primitive-typed, non-nested top-level properties. There is
deliberately no objectField/arrayField method, so a nested/object/array-typed field is a
compile-time impossibility, never a runtime-rejected one. build() additionally rejects a handful of
structurally-invalid per-field modifier combinations (for example format(String) on a non-string
field) with an IllegalStateException, so a handler author gets an immediate, in-process failure rather
than a wire-level schema-validation error discovered by the client much later.
Each xxxField(name) call starts a new field and becomes the target of every subsequent modifier call
(title(String), description(String), etc.) until the next xxxField(...) call.
Re-declaring a field under a name already used by an earlier xxxField(...) call replaces that
field's definition entirely, silently discarding any per-field modifiers already applied to it
(last-field-wins). minLength(int)/maxLength(int) are additional string-only per-field
modifiers, alongside format(String). required(String...) is a separate, builder-level (not
per-field) call that marks one or more field names required, emitting a top-level "required":[...]
array; unlike the per-field modifiers, it is not tied to the most-recently-started field, is order-independent
with respect to xxxField(...) (a name may be marked required before or after the field it names is
(re)declared, and a redeclaration of that field does not discard the marking), and may be called any time,
with an unknown name validated only at build() time.
Example:
JsonMap
-
Method Summary
Modifier and TypeMethodDescriptionbooleanField(String name) Starts aboolean-typed field.build()Validates every field's modifier combination (and the builder-levelrequired(String...)marking) and builds the final restricted-schemaJsonMap({"type":"object","properties":{...},"required":[...]}, the last member present only ifrequired(String...)was called at least once).static ElicitSchemacreate()Creates a new, empty schema builder.defaultValue(Object value) Sets the default value of the most-recently-started field.description(String value) Sets the description of the most-recently-started field.Starts a closed-choicestring-typed field restricted tovalues(wire shape:type:"string", enum:[...]).Sets parallel display labels for the most-recently-startedenumField(String, String...)'s values.Sets the string-subtype format of the most-recently-started field (for exampleemail,uri,date,date-time).integerField(String name) Starts aninteger-typed field.Sets the maximum value of the most-recently-started number/integer field.maxLength(int value) Sets the maximum UTF-16 code-unit length of the most-recently-started string field.Sets the minimum value of the most-recently-started number/integer field.minLength(int value) Sets the minimum UTF-16 code-unit length of the most-recently-started string field.numberField(String name) Starts anumber-typed (floating-point) field.Marks one or more already-added field names required, contributing to the built schema's top-level"required":[...]array.stringField(String name) Starts astring-typed field.Sets the display title of the most-recently-started field.
-
Method Details
-
create
Creates a new, empty schema builder.- Returns:
- A new builder. Never
null .
-
stringField
Starts astring-typed field.- Parameters:
name- The property name. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifnameisnull or blank.
-
numberField
Starts anumber-typed (floating-point) field.- Parameters:
name- The property name. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifnameisnull or blank.
-
integerField
Starts aninteger-typed field.- Parameters:
name- The property name. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifnameisnull or blank.
-
booleanField
Starts aboolean-typed field.- Parameters:
name- The property name. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifnameisnull or blank.
-
enumField
Starts a closed-choicestring-typed field restricted tovalues(wire shape:type:"string", enum:[...]). Pair withenumNames(String...)for parallel display labels.- Parameters:
name- The property name. Must not benull or blank.values- The allowed values. Must not benull or empty, and must not contain anull element.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifnameisnull or blank, orvaluesisnull , empty, or contains anull element.
-
title
Sets the display title of the most-recently-started field.- Parameters:
value- The title. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
description
Sets the description of the most-recently-started field.- Parameters:
value- The description. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
format
Sets the string-subtype format of the most-recently-started field (for exampleemail,uri,date,date-time). Applying this to a non-string field is rejected atbuild()time.- Parameters:
value- The format token. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
minLength
Sets the minimum UTF-16 code-unit length of the most-recently-started string field. Applying this to a non-string field, to anenumField(String, String...)(a closed-choice field, where a length constraint is meaningless), or a value that is negative or exceeds a previously-/subsequently-setmaxLength(int), is rejected atbuild()time.- Parameters:
value- The minimum length.- Returns:
- This object (for method chaining).
-
maxLength
Sets the maximum UTF-16 code-unit length of the most-recently-started string field. Applying this to a non-string field, to anenumField(String, String...)(a closed-choice field, where a length constraint is meaningless), or a value that is negative or less than a previously-/subsequently-setminLength(int), is rejected atbuild()time.- Parameters:
value- The maximum length.- Returns:
- This object (for method chaining).
-
min
Sets the minimum value of the most-recently-started number/integer field. Applying this to a field of any other type is rejected atbuild()time.- Parameters:
value- The minimum. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
max
Sets the maximum value of the most-recently-started number/integer field. Applying this to a field of any other type is rejected atbuild()time.- Parameters:
value- The maximum. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
defaultValue
Sets the default value of the most-recently-started field.Named
defaultValue, notdefault(a reserved Java keyword) — the wire schema property this writes is still literally"default".- Parameters:
value- The default value. Can benull .- Returns:
- This object (for method chaining).
-
enumNames
Sets parallel display labels for the most-recently-startedenumField(String, String...)'s values. Applying this to a field with noenumvalues is rejected atbuild()time.- Parameters:
values- The display labels, parallel in order to the field'senumvalues. Must not benull or empty, must not contain anull element, and (when the current field already carriesenumvalues) must be the same length as those values.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvaluesisnull , empty, or contains anull element, or if its length does not match the current field's existingenumvalues' length.
-
required
Marks one or more already-added field names required, contributing to the built schema's top-level"required":[...]array.Unlike the per-field modifiers (
title(String), etc.), this is a builder-level, not per-field, call — it is not tied to the most-recently-started field and may name any field(s) already added via an earlierxxxField(...)call, in any order. May be called more than once; each call adds to the previously-marked names (not replaced). Naming a field not (yet) added is rejected atbuild()time, not here, since a laterxxxField(...)call may still add it.- Parameters:
names- The field names to mark required. Must not benull or empty, and must not contain anull element.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifnamesisnull , empty, or contains anull element.
-
build
Validates every field's modifier combination (and the builder-levelrequired(String...)marking) and builds the final restricted-schemaJsonMap({"type":"object","properties":{...},"required":[...]}, the last member present only ifrequired(String...)was called at least once).- Returns:
- The built schema, ready for
ElicitRequest.setRequestedSchema(java.util.Map). - Throws:
IllegalStateException- If no field was ever added, if any field carries a structurally-invalid modifier combination, or ifrequired(String...)named a field that was never added.
-