internal/mcp/jsonschema: clearer validations errors
Validation errors now more clearly indicate the path from the root schema. - Enhance schema iteration to yield the path, and generalize it by using reflection. - Store each schema's path inside the schema. - Remove the path arg from validate: we don't need it anymore. - Improve the test for the iterators and add one for validation errors. Change-Id: Ief55133ef4ae2eac0736208a3b9f78ed69933b31 Reviewed-on: https://go-review.googlesource.com/c/tools/+/676375 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
parent
7130f0f081
commit
e3938ce68c
1 changed files with 185 additions and 106 deletions
|
|
@ -78,6 +78,21 @@ func TestValidate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestValidateErrors(t *testing.T) {
|
||||
schema := &Schema{
|
||||
PrefixItems: []*Schema{{Contains: &Schema{Type: "integer"}}},
|
||||
}
|
||||
rs, err := schema.Resolve("", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = rs.Validate([]any{[]any{"1"}})
|
||||
want := "prefixItems/0"
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("error:\n%s\ndoes not contain %q", err, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStructInstance(t *testing.T) {
|
||||
instance := struct {
|
||||
I int
|
||||
|
|
|
|||
Loading…
Reference in a new issue