File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ package jsonschema
2
+
3
+ import "testing"
4
+
5
+ // TestContainsRef ensures containsRef recursively searches definitions and items.
6
+ func TestContainsRef (t * testing.T ) {
7
+ schema := Definition {
8
+ Type : Object ,
9
+ Properties : map [string ]Definition {
10
+ "person" : {Ref : "#/$defs/Person" },
11
+ },
12
+ Defs : map [string ]Definition {
13
+ "Person" : {
14
+ Type : Object ,
15
+ Properties : map [string ]Definition {
16
+ "friends" : {
17
+ Type : Array ,
18
+ Items : & Definition {Ref : "#/$defs/Person" },
19
+ },
20
+ },
21
+ },
22
+ },
23
+ }
24
+
25
+ if ! containsRef (schema , "#/$defs/Person" ) {
26
+ t .Fatal ("expected to find reference in root" )
27
+ }
28
+ if ! containsRef (schema .Defs ["Person" ], "#/$defs/Person" ) {
29
+ t .Fatal ("expected to find self reference in defs" )
30
+ }
31
+ if containsRef (schema , "#/$defs/Unknown" ) {
32
+ t .Fatal ("unexpected reference found" )
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ package jsonschema_test
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/sashabaranov/go-openai/jsonschema"
7
+ )
8
+
9
+ // TestGenerateSchemaForType_ErrorPaths verifies error handling for unsupported types.
10
+ func TestGenerateSchemaForType_ErrorPaths (t * testing.T ) {
11
+ type anon struct { Ch chan int }
12
+ tests := []struct {
13
+ name string
14
+ v any
15
+ }{
16
+ {"slice" , []chan int {}},
17
+ {"anon struct" , anon {}},
18
+ {"pointer" , (* chan int )(nil )},
19
+ }
20
+ for _ , tt := range tests {
21
+ t .Run (tt .name , func (t * testing.T ) {
22
+ if _ , err := jsonschema .GenerateSchemaForType (tt .v ); err == nil {
23
+ t .Errorf ("expected error for %s" , tt .name )
24
+ }
25
+ })
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments