Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Disallow additional schema props #325

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk-go/inferable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions sdk-go/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Loading