From 82e16a57fccfdc7d756295133452afb404d5216b Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 16 Dec 2024 19:54:37 +1030 Subject: [PATCH] chore: Formatting --- sdk-go/inferable_test.go | 2 ++ sdk-go/main_test.go | 3 --- sdk-go/service.go | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/sdk-go/inferable_test.go b/sdk-go/inferable_test.go index a0762ab9..49754aa5 100644 --- a/sdk-go/inferable_test.go +++ b/sdk-go/inferable_test.go @@ -199,6 +199,7 @@ func TestGetSchema(t *testing.T) { "TestFunc": { "name": "TestFunc", "input": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "a": {"type": "integer"}, @@ -210,6 +211,7 @@ func TestGetSchema(t *testing.T) { "TestFunc2": { "name": "TestFunc2", "input": { + "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "c": { diff --git a/sdk-go/main_test.go b/sdk-go/main_test.go index 1958149a..3ebe87b3 100644 --- a/sdk-go/main_test.go +++ b/sdk-go/main_test.go @@ -62,12 +62,9 @@ func TestInferableFunctions(t *testing.T) { t.Fatalf("Error registering reverse function: %v", err) } - jsonDef, err := inferableInstance.toJSONDefinition() if err != nil { t.Fatalf("Error generating JSON definition: %v", err) } - t.Logf("JSON Definition:\n%s\n", string(jsonDef)) - t.Run("Echo Function", func(t *testing.T) { testInput := EchoInput{Input: "Hello, Inferable!"} result, err := inferableInstance.callFunc("string_operations", "echo", testInput) diff --git a/sdk-go/service.go b/sdk-go/service.go index 72b054c4..b3e2d5fd 100644 --- a/sdk-go/service.go +++ b/sdk-go/service.go @@ -106,18 +106,18 @@ func (s *service) RegisterFunc(fn Function) (*FunctionReference, error) { } argType := fnType.In(0) - // Set the argument type to the referenced type - if argType.Kind() == reflect.Ptr { - argType = argType.Elem() - } - - if argType.Kind() != reflect.Struct { - return nil, fmt.Errorf("function '%s' first argument must be a struct or a pointer to a struct", fn.Name) - } - - // Get the schema for the input struct - reflector := jsonschema.Reflector{DoNotReference: true} - schema := reflector.Reflect(reflect.New(argType).Interface()) + // Set the argument type to the referenced type + if argType.Kind() == reflect.Ptr { + argType = argType.Elem() + } + + if argType.Kind() != reflect.Struct { + return nil, fmt.Errorf("function '%s' first argument must be a struct or a pointer to a struct", fn.Name) + } + + // Get the schema for the input struct + reflector := jsonschema.Reflector{DoNotReference: true, Anonymous: true} + schema := reflector.Reflect(reflect.New(argType).Interface()) if schema == nil { return nil, fmt.Errorf("failed to get schema for function '%s'", fn.Name)