Do not wrap pointer-to-struct functool inputs#527
Open
PratikDhanave wants to merge 1 commit into
Open
Conversation
inputFormatFor wrapped any input whose Kind is not Struct in inputWrapper[T].
A pointer-to-struct handler (func(ctx, *In)) has Kind Ptr, so it was wrapped,
producing a nested {"Arg0":{...}} schema and rejecting the flat arguments a
value-receiver (func(ctx, In)) handler accepts — even though jsonformat.ForType
deliberately dereferences pointers to produce the same flat schema.
Dereference pointers before the struct check so *Struct and Struct inputs
behave identically; only genuinely non-struct inputs are wrapped.
Adds a black-box test that a *struct input accepts flat arguments.
There was a problem hiding this comment.
Pull request overview
This PR aligns functool input schema generation with jsonformat.ForType by ensuring pointer-to-struct (*Struct) handler inputs are treated the same as value struct (Struct) inputs, avoiding an unnecessary root-level wrapper schema that breaks flat JSON arguments.
Changes:
- Dereference pointer types before deciding whether to wrap the input type in
inputWrapper[T]. - Preserve wrapping only for genuinely non-struct root inputs.
- Add a black-box test proving
*structhandlers accept flat JSON arguments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tool/functool/func.go |
Dereferences pointer inputs before the struct-kind check to prevent *struct from being wrapped and producing nested schemas. |
tool/functool/func_test.go |
Adds a regression test validating that *struct inputs use a flat schema and accept flat JSON args. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
inputFormatFor(tool/functool/func.go) wraps any input whoseKindis notreflect.StructininputWrapper[T]. A pointer-to-struct handler hasKind == reflect.Ptr, so it gets wrapped — producing a nested{"Arg0":{...}}schema and rejecting the flat arguments that the equivalent value-receiver handler accepts:This contradicts
jsonformat.ForType, which deliberately dereferences pointers at the root ("Pointers are treated equivalently to non-pointers … with no benefit" to wrapping the root object). So*StructandStructhandlers should produce the same flat schema, but today onlyStructdoes.Fix
Dereference pointers before the struct check, so only genuinely non-struct inputs are wrapped.
Public API
No exported symbols change.
Tests
Adds
TestFuncTool_PointerStructInput_UsesFlatSchema(black-box): a*structhandler accepts flat arguments. It fails before this change (schema validation rejects the flat args) and passes after.