jsonschema: add more schema fields
Add additional fields to Schema which are mentioned in the spec but do not affect validation. Change-Id: I89488261a00c207d01cd7fc59d782f43692fe528 Reviewed-on: https://go-review.googlesource.com/c/tools/+/674976 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
715e9f1935
commit
fdbd35a415
1 changed files with 134 additions and 17 deletions
|
|
@ -24,6 +24,7 @@ func TestGoRoundTrip(t *testing.T) {
|
|||
{Const: Ptr(any(nil))},
|
||||
{Const: Ptr(any([]int{}))},
|
||||
{Const: Ptr(any(map[string]any{}))},
|
||||
{Default: Ptr(any(nil))},
|
||||
} {
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
|
|
@ -31,9 +32,7 @@ func TestGoRoundTrip(t *testing.T) {
|
|||
}
|
||||
t.Logf("marshal: %s", data)
|
||||
var got *Schema
|
||||
if err := json.Unmarshal(data, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustUnmarshal(t, data, &got)
|
||||
if !Equal(got, s) {
|
||||
t.Errorf("got %+v, want %+v", got, s)
|
||||
if got.Const != nil && s.Const != nil {
|
||||
|
|
@ -68,9 +67,7 @@ func TestJSONRoundTrip(t *testing.T) {
|
|||
{`{"unk":0}`, `{}`}, // unknown fields are dropped, unfortunately
|
||||
} {
|
||||
var s Schema
|
||||
if err := json.Unmarshal([]byte(tt.in), &s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustUnmarshal(t, []byte(tt.in), &s)
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -126,3 +123,10 @@ func TestEvery(t *testing.T) {
|
|||
t.Errorf("got %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func mustUnmarshal(t *testing.T, data []byte, ptr any) {
|
||||
t.Helper()
|
||||
if err := json.Unmarshal(data, ptr); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue