(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestExtractJSONPathFromValidationError(t *testing.T) { |
| 102 | // Create a schema with validation errors |
| 103 | schemaJSON := `{ |
| 104 | "type": "object", |
| 105 | "properties": { |
| 106 | "name": {"type": "string"}, |
| 107 | "age": {"type": "number"}, |
| 108 | "tools": { |
| 109 | "type": "array", |
| 110 | "items": { |
| 111 | "type": "object", |
| 112 | "properties": { |
| 113 | "name": {"type": "string"} |
| 114 | }, |
| 115 | "required": ["name"] |
| 116 | } |
| 117 | } |
| 118 | }, |
| 119 | "additionalProperties": false |
| 120 | }` |
| 121 | |
| 122 | // Create invalid data |
| 123 | invalidData := map[string]any{ |
| 124 | "name": "John", |
| 125 | "age": "not-a-number", // Should be number |
| 126 | "invalid_key": "value", // Additional property not allowed |
| 127 | "tools": []any{ |
| 128 | map[string]any{ |
| 129 | "name": "tool1", |
| 130 | }, |
| 131 | map[string]any{ |
| 132 | // Missing required "name" field |
| 133 | "description": "tool without name", |
| 134 | }, |
| 135 | }, |
| 136 | } |
| 137 | |
| 138 | // Compile schema and validate |
| 139 | compiler := jsonschema.NewCompiler() |
| 140 | var schemaDoc any |
| 141 | if err := json.Unmarshal([]byte(schemaJSON), &schemaDoc); err != nil { |
| 142 | t.Fatalf("json.Unmarshal error: %v", err) |
| 143 | } |
| 144 | |
| 145 | schemaURL := "http://example.com/schema.json" |
| 146 | compiler.AddResource(schemaURL, schemaDoc) |
| 147 | schema, err := compiler.Compile(schemaURL) |
| 148 | if err != nil { |
| 149 | t.Fatalf("Schema compilation error: %v", err) |
| 150 | } |
| 151 | |
| 152 | err = schema.Validate(invalidData) |
| 153 | if err == nil { |
| 154 | t.Fatal("Expected validation error, got nil") |
| 155 | } |
| 156 | |
| 157 | // Extract JSON path information |
| 158 | paths := ExtractJSONPathFromValidationError(err) |
nothing calls this directly
no test coverage detected