...
1
16
17 package explain
18
19 import (
20 "fmt"
21
22 "k8s.io/kube-openapi/pkg/util/proto"
23 )
24
25
26 type typeName struct {
27 Name string
28 }
29
30 var _ proto.SchemaVisitor = &typeName{}
31
32
33 func (t *typeName) VisitArray(a *proto.Array) {
34 s := &typeName{}
35 a.SubType.Accept(s)
36 t.Name = fmt.Sprintf("[]%s", s.Name)
37 }
38
39
40 func (t *typeName) VisitKind(k *proto.Kind) {
41 t.Name = "Object"
42 }
43
44
45 func (t *typeName) VisitMap(m *proto.Map) {
46 s := &typeName{}
47 m.SubType.Accept(s)
48 t.Name = fmt.Sprintf("map[string]%s", s.Name)
49 }
50
51
52 func (t *typeName) VisitPrimitive(p *proto.Primitive) {
53 t.Name = p.Type
54 }
55
56
57 func (t *typeName) VisitReference(r proto.Reference) {
58 r.SubSchema().Accept(t)
59 }
60
61
62 func GetTypeName(schema proto.Schema) string {
63 t := &typeName{}
64 schema.Accept(t)
65 return t.Name
66 }
67
View as plain text