MCPcopy Create free account
hub / github.com/dropbox/dbxcli / compileJSONSchemaFile

Function compileJSONSchemaFile

cmd/json_command_schema_test.go:343–367  ·  view source on GitHub ↗
(t *testing.T, file string)

Source from the content-addressed store, hash-verified

341}
342
343func 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
369func assertJSONBytesValidateAgainstSchema(t *testing.T, schema *jsonschema.Schema, data []byte) {
370 t.Helper()

Calls 2

readJSONFileFunction · 0.85
decodeJSONValueForSchemaFunction · 0.85

Tested by

no test coverage detected