Package com.tnsai.tools.method
Class JsonSchemaGenerator
java.lang.Object
com.tnsai.tools.method.JsonSchemaGenerator
Builds JSON Schema fragments for
ToolMethod parameters from their
static Java Types.
The output shape matches what LLM tool-calling APIs expect — see for
instance OpenAI's function.parameters, Anthropic's input_schema,
Gemini's parameters. All three converge on the same JSON Schema
subset.
Supported types
| Java type | JSON Schema |
|---|---|
String, char, Character | "string" |
int / Integer / long / Long / short / Short / byte / Byte | "integer" |
float / Float / double / Double | "number" |
boolean / Boolean | "boolean" |
Enum subclasses | "string" + enum: [VALUES] |
List<T>, Set<T>, T[] | "array" + items: {…} |
Map<String, V> | "object" + additionalProperties: {…} |
| Other reference types | "object" (no properties — recursive POJO support deferred) |
Recursive POJO schema generation is intentionally out of scope for the Phase 1 implementation — most tool methods use primitives + collections of primitives. POJO parameters can be added later without breaking the contract: callers will see strictly more detail in the schema, never less.
- Since:
- 0.5.7 (LangChain-style tool refactor — see issue #188)
-
Method Summary
Modifier and TypeMethodDescriptionparameterSchema(ToolParameter param) Build the schema for a single parameter — type + description + enum constraints when applicable.parametersSchema(ToolMethod tool) Build the fullparametersobject for a tool method — the value that goes underfunction.parametersin OpenAI's tool definition (orinput_schemain Anthropic's).typeSchema(Type type) Map a JavaTypeto its JSON Schema fragment.
-
Method Details
-
parametersSchema
Build the fullparametersobject for a tool method — the value that goes underfunction.parametersin OpenAI's tool definition (orinput_schemain Anthropic's).- Parameters:
tool- the discovered tool method- Returns:
- a
Mapsuitable for JSON serialization (Jackson, Gson, …)
-
parameterSchema
Build the schema for a single parameter — type + description + enum constraints when applicable. -
typeSchema
Map a JavaTypeto its JSON Schema fragment. Public for tests and reuse — most callers wantparameterSchema(ToolParameter).
-