Supercedes #1999
Closes #1794
Summary
Adds an optional schema attribute to @CopilotToolParam that allows users to explicitly specify the JSON Schema for a tool parameter. This enables support for custom/third-party types that the SchemaGenerator cannot automatically map.
Example
@CopilotTool("Schedule a deployment")
public String scheduleDeployment(
@CopilotToolParam(value = "Deployment time in ISO-8601",
schema = "{\"type\":\"string\",\"format\":\"date-time\"}")
com.acme.internal.AcmeDateTime deployTime) {
return "Scheduled for " + deployTime;
}
Changes
CopilotToolParam.java
- Added
String schema() default "" annotation attribute with Javadoc
CopilotToolProcessor.java
- In
generateSchemaWithParamMetadata(): when schema is non-empty, use it instead of auto-generated schema
- Added compile-time validation:
schema + defaultValue conflict emits error
- Added compile-time validation: invalid JSON (not starting/ending with braces) emits error
- Added
jsonToMapOfSource() — a minimal recursive-descent JSON parser that converts JSON strings to Map.of(...) source code expressions at compile time (no external JSON library needed)
Param.java
- Added
schema field, fluent schema() mutator, and getter for lambda API parity
- Updated
equals(), hashCode() to include schema
CopilotToolProcessorTest.java (4 new tests)
- Schema override — custom schema appears in generated code
- Schema + defaultValue conflict — produces compile error
- Invalid JSON — produces compile error
- Empty schema — falls through to normal type-based generation
Testing
- All 4 new tests pass
- The only failing test (
generatesNullMetadata_whenAbsent) is a pre-existing failure on main unrelated to this PR
Supercedes #1999
Closes #1794
Summary
Adds an optional
schemaattribute to@CopilotToolParamthat allows users to explicitly specify the JSON Schema for a tool parameter. This enables support for custom/third-party types that theSchemaGeneratorcannot automatically map.Example
Changes
CopilotToolParam.javaString schema() default ""annotation attribute with JavadocCopilotToolProcessor.javagenerateSchemaWithParamMetadata(): whenschemais non-empty, use it instead of auto-generated schemaschema+defaultValueconflict emits errorjsonToMapOfSource()— a minimal recursive-descent JSON parser that converts JSON strings toMap.of(...)source code expressions at compile time (no external JSON library needed)Param.javaschemafield, fluentschema()mutator, and getter for lambda API parityequals(),hashCode()to includeschemaCopilotToolProcessorTest.java(4 new tests)Testing
generatesNullMetadata_whenAbsent) is a pre-existing failure onmainunrelated to this PR