| 1 | package anthropicscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.23.0 `encoding/json`/" |
| 5 | "reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/" |
| 7 | ) |
| 8 | |
| 9 | func TestTransformSchemascip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go`/TestTransformSchema().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 10 | tests := []struct { |
| 11 | name string |
| 12 | input map[string]any |
| 13 | expected map[string]any |
| 14 | }{ |
| 15 | { |
| 16 | name: "basic integer with unsupported properties", |
| 17 | input: map[string]any{ |
| 18 | "type": "integer", |
| 19 | "minimum": 1, |
| 20 | "maximum": 10, |
| 21 | "description": "A number", |
| 22 | }, |
| 23 | expected: map[string]any{ |
| 24 | "type": "integer", |
| 25 | "description": "A number\n\n{maximum: 10, minimum: 1}", |
| 26 | }, |
| 27 | }, |
| 28 | { |
| 29 | name: "object with properties", |
| 30 | input: map[string]any{ |
| 31 | "type": "object", |
| 32 | "properties": map[string]any{ |
| 33 | "name": map[string]any{ |
| 34 | "type": "string", |
| 35 | }, |
| 36 | "age": map[string]any{ |
| 37 | "type": "integer", |
| 38 | }, |
| 39 | }, |
| 40 | "required": []string{"name"}, |
| 41 | "additionalProperties": true, |
| 42 | }, |
| 43 | expected: map[string]any{ |
| 44 | "type": "object", |
| 45 | "properties": map[string]any{ |
| 46 | "name": map[string]any{ |
| 47 | "type": "string", |
| 48 | }, |
| 49 | "age": map[string]any{ |
| 50 | "type": "integer", |
| 51 | }, |
| 52 | }, |
| 53 | "required": []string{"name"}, |
| 54 | "additionalProperties": false, |
| 55 | }, |
| 56 | }, |
| 57 | { |
| 58 | name: "string with supported format", |
| 59 | input: map[string]any{ |
| 60 | "type": "string", |
| 61 | "format": "date-time", |
| 62 | }, |
| 63 | expected: map[string]any{ |
| 64 | "type": "string", |
| 65 | "format": "date-time", |
| 66 | }, |
| 67 | }, |
| 68 | { |
| 69 | name: "string with unsupported format", |
| 70 | input: map[string]any{ |
| 71 | "type": "string", |
| 72 | "format": "binary", |
| 73 | }, |
| 74 | expected: map[string]any{ |
| 75 | "type": "string", |
| 76 | "description": "{format: binary}", |
| 77 | }, |
| 78 | }, |
| 79 | { |
| 80 | name: "array with minItems 1", |
| 81 | input: map[string]any{ |
| 82 | "type": "array", |
| 83 | "items": map[string]any{ |
| 84 | "type": "string", |
| 85 | }, |
| 86 | "minItems": 1, |
| 87 | }, |
| 88 | expected: map[string]any{ |
| 89 | "type": "array", |
| 90 | "items": map[string]any{ |
| 91 | "type": "string", |
| 92 | }, |
| 93 | "minItems": 1, |
| 94 | }, |
| 95 | }, |
| 96 | { |
| 97 | name: "array with minItems 5", |
| 98 | input: map[string]any{ |
| 99 | "type": "array", |
| 100 | "items": map[string]any{ |
| 101 | "type": "string", |
| 102 | }, |
| 103 | "minItems": 5, |
| 104 | }, |
| 105 | expected: map[string]any{ |
| 106 | "type": "array", |
| 107 | "items": map[string]any{ |
| 108 | "type": "string", |
| 109 | }, |
| 110 | "description": "{minItems: 5}", |
| 111 | }, |
| 112 | }, |
| 113 | { |
| 114 | name: "schema with $ref", |
| 115 | input: map[string]any{ |
| 116 | "$ref": "#/definitions/Person", |
| 117 | "type": "object", |
| 118 | }, |
| 119 | expected: map[string]any{ |
| 120 | "$ref": "#/definitions/Person", |
| 121 | }, |
| 122 | }, |
| 123 | { |
| 124 | name: "schema with anyOf", |
| 125 | input: map[string]any{ |
| 126 | "anyOf": []any{ |
| 127 | map[string]any{ |
| 128 | "type": "string", |
| 129 | }, |
| 130 | map[string]any{ |
| 131 | "type": "number", |
| 132 | }, |
| 133 | }, |
| 134 | }, |
| 135 | expected: map[string]any{ |
| 136 | "anyOf": []any{ |
| 137 | map[string]any{ |
| 138 | "type": "string", |
| 139 | }, |
| 140 | map[string]any{ |
| 141 | "type": "number", |
| 142 | }, |
| 143 | }, |
| 144 | }, |
| 145 | }, |
| 146 | { |
| 147 | name: "schema with oneOf converted to anyOf", |
| 148 | input: map[string]any{ |
| 149 | "oneOf": []any{ |
| 150 | map[string]any{ |
| 151 | "type": "string", |
| 152 | }, |
| 153 | map[string]any{ |
| 154 | "type": "number", |
| 155 | }, |
| 156 | }, |
| 157 | }, |
| 158 | expected: map[string]any{ |
| 159 | "anyOf": []any{ |
| 160 | map[string]any{ |
| 161 | "type": "string", |
| 162 | }, |
| 163 | map[string]any{ |
| 164 | "type": "number", |
| 165 | }, |
| 166 | }, |
| 167 | }, |
| 168 | }, |
| 169 | { |
| 170 | name: "schema with $defs", |
| 171 | input: map[string]any{ |
| 172 | "type": "object", |
| 173 | "$defs": map[string]any{ |
| 174 | "Person": map[string]any{ |
| 175 | "type": "object", |
| 176 | "properties": map[string]any{ |
| 177 | "name": map[string]any{ |
| 178 | "type": "string", |
| 179 | }, |
| 180 | }, |
| 181 | }, |
| 182 | }, |
| 183 | "properties": map[string]any{ |
| 184 | "user": map[string]any{ |
| 185 | "$ref": "#/$defs/Person", |
| 186 | }, |
| 187 | }, |
| 188 | }, |
| 189 | expected: map[string]any{ |
| 190 | "type": "object", |
| 191 | "$defs": map[string]any{ |
| 192 | "Person": map[string]any{ |
| 193 | "type": "object", |
| 194 | "properties": map[string]any{ |
| 195 | "name": map[string]any{ |
| 196 | "type": "string", |
| 197 | }, |
| 198 | }, |
| 199 | "additionalProperties": false, |
| 200 | }, |
| 201 | }, |
| 202 | "properties": map[string]any{ |
| 203 | "user": map[string]any{ |
| 204 | "$ref": "#/$defs/Person", |
| 205 | }, |
| 206 | }, |
| 207 | "additionalProperties": false, |
| 208 | }, |
| 209 | }, |
| 210 | { |
| 211 | name: "nil schema returns nil", |
| 212 | input: nil, |
| 213 | expected: nil, |
| 214 | }, |
| 215 | { |
| 216 | name: "schema without type returns nil", |
| 217 | input: map[string]any{ |
| 218 | "description": "A schema without type", |
| 219 | }, |
| 220 | expected: nil, |
| 221 | }, |
| 222 | } |
| 223 | |
| 224 | for _, tt := range tests { |
| 225 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 226 | result := transformSchemascip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go`/transformSchema().(tt.input) |
| 227 | if !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(result, tt.expected) { |
| 228 | resultJSON, _ := jsonscip-go gomod github.com/golang/go/src go1.23.0 `encoding/json`/.MarshalIndentscip-go gomod github.com/golang/go/src go1.23.0 `encoding/json`/MarshalIndent().(result, "", " ") |
| 229 | expectedJSON, _ := jsonscip-go gomod github.com/golang/go/src go1.23.0 `encoding/json`/.MarshalIndentscip-go gomod github.com/golang/go/src go1.23.0 `encoding/json`/MarshalIndent().(tt.expected, "", " ") |
| 230 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("TransformSchema() mismatch:\ngot:\n%s\nwant:\n%s", resultJSON, expectedJSON) |
| 231 | } |
| 232 | }) |
| 233 | } |
| 234 | } |