...
1
16
17 package openapi
18
19 import (
20 "encoding/json"
21 "reflect"
22 "testing"
23
24 "github.com/google/go-cmp/cmp"
25 "k8s.io/kube-openapi/pkg/common"
26 "k8s.io/kube-openapi/pkg/handler"
27 "k8s.io/kube-openapi/pkg/validation/spec"
28 )
29
30 func TestOpenAPIRoundtrip(t *testing.T) {
31 dummyRef := func(name string) spec.Ref { return spec.MustCreateRef("#/definitions/dummy") }
32 for name, value := range GetOpenAPIDefinitions(dummyRef) {
33 t.Run(name, func(t *testing.T) {
34
35 value.Schema = *handler.PruneDefaultsSchema(&value.Schema)
36 data, err := json.Marshal(value.Schema)
37 if err != nil {
38 t.Error(err)
39 return
40 }
41
42 roundTripped := spec.Schema{}
43 if err := json.Unmarshal(data, &roundTripped); err != nil {
44 t.Error(err)
45 return
46 }
47
48
49
50
51 delete(roundTripped.Extensions, common.ExtensionV2Schema)
52 delete(value.Schema.Extensions, common.ExtensionV2Schema)
53
54 if !reflect.DeepEqual(value.Schema, roundTripped) {
55 t.Errorf("unexpected diff (a=expected,b=roundtripped):\n%s", cmp.Diff(value.Schema, roundTripped))
56 return
57 }
58 })
59 }
60 }
61
View as plain text