java: add schema attribute to @CopilotToolParam for custom type schema override#1999
java: add schema attribute to @CopilotToolParam for custom type schema override#1999rinceyuan wants to merge 3 commits into
Conversation
…a override Closes github#1794 Add an optional schema attribute to @CopilotToolParam that allows users to explicitly specify the JSON Schema for a tool parameter, bypassing automatic type-based schema generation. Changes: - CopilotToolParam.java: add String schema() default "" - CopilotToolProcessor.java: use custom schema when provided, with compile-time JSON validation and schema+defaultValue conflict check. Includes a minimal recursive-descent JSON-to-Map.of() converter. - Param.java: add schema field + fluent mutator for lambda API parity - CopilotToolProcessorTest.java: 4 new tests
|
@microsoft-github-policy-service agree company=Microsoft |
There was a problem hiding this comment.
Pull request overview
Adds explicit JSON Schema overrides for Java tool parameters.
Changes:
- Extends annotation and fluent parameter APIs with
schema. - Validates and converts JSON overrides during annotation processing.
- Adds processor tests for basic override and validation paths.
Show a summary per file
| File | Description |
|---|---|
CopilotToolParam.java |
Adds the annotation attribute and Javadoc. |
Param.java |
Adds fluent schema metadata support. |
CopilotToolProcessor.java |
Validates and converts schema JSON into generated Java. |
CopilotToolProcessorTest.java |
Tests basic override behavior and errors. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 7
- Review effort level: Medium
Review finding: schema override missing from tools-as-lambda pathThe PR adds the schema attribute to @CopilotToolParam and the annotation processor correctly uses it to bypass auto-generated schema. It also adds the schema field and fluent setter to Param.java. However, the tools-as-lambda path (ToolDefinition.from(...) → ParamSchema.buildSchema()) does not consume Param.schema(). In ParamSchema.java line 87, schema generation always calls orType(param.type()) regardless of whether a schema override is set:
This means a user who defines a tool inline like:
…would still get the auto-derived schema from orType(), not the explicit override. I am working now to address this gap and will follow up. |
|
Superceded by #2069 |
Closes #1794
Superseded by #2069
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