From 5c64a80e96587bec0b8547a608cca0ebac2b50ec Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 17 Dec 2024 10:50:57 +1030 Subject: [PATCH] chore: Disallow additional schema props --- sdk-go/inferable_test.go | 2 ++ sdk-go/service.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk-go/inferable_test.go b/sdk-go/inferable_test.go index 49754aa..559b17e 100644 --- a/sdk-go/inferable_test.go +++ b/sdk-go/inferable_test.go @@ -200,6 +200,7 @@ func TestGetSchema(t *testing.T) { "name": "TestFunc", "input": { "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, "type": "object", "properties": { "a": {"type": "integer"}, @@ -212,6 +213,7 @@ func TestGetSchema(t *testing.T) { "name": "TestFunc2", "input": { "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, "type": "object", "properties": { "c": { diff --git a/sdk-go/service.go b/sdk-go/service.go index b3e2d5f..0c9cd8f 100644 --- a/sdk-go/service.go +++ b/sdk-go/service.go @@ -116,7 +116,7 @@ func (s *service) RegisterFunc(fn Function) (*FunctionReference, error) { } // Get the schema for the input struct - reflector := jsonschema.Reflector{DoNotReference: true, Anonymous: true} + reflector := jsonschema.Reflector{DoNotReference: true, Anonymous: true, AllowAdditionalProperties: false} schema := reflector.Reflect(reflect.New(argType).Interface()) if schema == nil { @@ -142,7 +142,7 @@ func (s *service) RegisterFunc(fn Function) (*FunctionReference, error) { return nil, fmt.Errorf("schema for function '%s' contains a $ref to an external definition. this is currently not supported. see https://go.inferable.ai/go-schema-limitation for details", fn.Name) } - defs.AdditionalProperties = nil + defs.AdditionalProperties = jsonschema.FalseSchema fn.schema = defs s.Functions[fn.Name] = fn