(t *testing.T, file string)
| 341 | } |
| 342 | |
| 343 | func compileJSONSchemaFile(t *testing.T, file string) *jsonschema.Schema { |
| 344 | t.Helper() |
| 345 | |
| 346 | data := readJSONFile(t, file) |
| 347 | doc := decodeJSONValueForSchema(t, data) |
| 348 | object, ok := doc.(map[string]any) |
| 349 | if !ok { |
| 350 | t.Fatalf("%s schema root is %T, want object", file, doc) |
| 351 | } |
| 352 | id, ok := object["$id"].(string) |
| 353 | if !ok || id == "" { |
| 354 | t.Fatalf("%s schema has no $id", file) |
| 355 | } |
| 356 | |
| 357 | compiler := jsonschema.NewCompiler() |
| 358 | compiler.DefaultDraft(jsonschema.Draft2020) |
| 359 | if err := compiler.AddResource(id, doc); err != nil { |
| 360 | t.Fatalf("add schema resource %s: %v", file, err) |
| 361 | } |
| 362 | schema, err := compiler.Compile(id) |
| 363 | if err != nil { |
| 364 | t.Fatalf("compile schema %s: %v", file, err) |
| 365 | } |
| 366 | return schema |
| 367 | } |
| 368 | |
| 369 | func assertJSONBytesValidateAgainstSchema(t *testing.T, schema *jsonschema.Schema, data []byte) { |
| 370 | t.Helper() |
no test coverage detected