internal/mcp/jsonschema: apply schema defaults to an instance
This CL handles only the limited case of defaults on properties. This is just a start: I need to think more about defaults on other schema keywords, and I need to set defaults recursively. As part of this work, I realized that the Schema.Default field is more usable when represented as a json.RawMessage instead of a *any. Change-Id: Iedcedb405b52607a312dbd895fa61e7f7f94c6bc Reviewed-on: https://go-review.googlesource.com/c/tools/+/676938 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
parent
a9a69a03e4
commit
c5a3591742
1 changed files with 187 additions and 25 deletions
|
|
@ -24,17 +24,17 @@ func TestGoRoundTrip(t *testing.T) {
|
|||
{Const: Ptr(any(nil))},
|
||||
{Const: Ptr(any([]int{}))},
|
||||
{Const: Ptr(any(map[string]any{}))},
|
||||
{Default: Ptr(any(nil))},
|
||||
{Default: mustMarshal(1)},
|
||||
{Default: mustMarshal(nil)},
|
||||
} {
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("marshal: %s", data)
|
||||
var got *Schema
|
||||
mustUnmarshal(t, data, &got)
|
||||
if !Equal(got, s) {
|
||||
t.Errorf("got %+v, want %+v", got, s)
|
||||
t.Errorf("got %s, want %s", got.json(), s.json())
|
||||
if got.Const != nil && s.Const != nil {
|
||||
t.Logf("Consts: got %#v (%[1]T), want %#v (%[2]T)", *got.Const, *s.Const)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue