-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_type_polymorphic_base.go
116 lines (95 loc) · 2.78 KB
/
rest_type_polymorphic_base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) Topicus Security B.V.
// SPDX-License-Identifier: APSL-2.0
package model
import "sort"
type restPolymorphicBaseClassType struct {
reachable bool
nestedType RestType
subtypes []RestType
dsType *restPolymorphicBaseClassType
}
func NewRestPolymorphicBaseClassType(nestedType RestType) RestType {
return &restPolymorphicBaseClassType{
nestedType: nestedType,
subtypes: make([]RestType, 0),
}
}
func (t *restPolymorphicBaseClassType) Reachable() bool {
return t.reachable
}
func (t *restPolymorphicBaseClassType) MarkReachable() {
if t.reachable {
return
}
t.reachable = true
t.nestedType.MarkReachable()
sort.Slice(t.subtypes, func(i, j int) bool {
return t.subtypes[i].APITypeName() < t.subtypes[j].APITypeName()
})
for _, sub := range t.subtypes {
sub.MarkReachable()
}
}
func (t *restPolymorphicBaseClassType) Extends(typeName string) bool {
return t.nestedType.Extends(typeName)
}
func (t *restPolymorphicBaseClassType) IsObject() bool {
return t.nestedType.IsObject()
}
func (t *restPolymorphicBaseClassType) ObjectAttrTypesName() string {
return t.nestedType.ObjectAttrTypesName()
}
func (t *restPolymorphicBaseClassType) DataStructName() string {
return t.nestedType.DataStructName()
}
func (t *restPolymorphicBaseClassType) APITypeName() string {
return t.nestedType.APITypeName()
}
func (t *restPolymorphicBaseClassType) APIDiscriminator() string {
return t.nestedType.APIDiscriminator()
}
func (t *restPolymorphicBaseClassType) GoTypeName() string {
return t.nestedType.GoTypeName()
}
func (t *restPolymorphicBaseClassType) SDKTypeName() string {
return t.nestedType.SDKTypeName()
}
func (t *restPolymorphicBaseClassType) SDKTypeConstructor() string {
return t.nestedType.SDKTypeConstructor()
}
func (t *restPolymorphicBaseClassType) AllProperties() []*RestProperty {
ret := make([]*RestProperty, 0)
ret = append(ret, t.nestedType.AllProperties()...)
for _, subtype := range t.subtypes {
prop := &RestProperty{
Parent: t.nestedType,
Name: FirstCharToLower(StripLowercasePrefix(subtype.APITypeName())),
Required: false,
WriteOnly: false,
Deprecated: false,
}
prop.Type = NewPolymorphicSubtype(prop, t, subtype)
ret = append(ret, prop)
}
return ret
}
func (t *restPolymorphicBaseClassType) HasDirectUUIDProperty() bool {
return t.nestedType.HasDirectUUIDProperty()
}
func (t *restPolymorphicBaseClassType) Suffix() string {
return t.nestedType.Suffix()
}
func (t *restPolymorphicBaseClassType) DS() RestType {
if t.dsType != nil {
// break recursion
return t.dsType
}
t.dsType = &restPolymorphicBaseClassType{
nestedType: t.nestedType.DS(),
}
t.dsType.subtypes = make([]RestType, 0)
for _, subtype := range t.subtypes {
t.dsType.subtypes = append(t.dsType.subtypes, subtype.DS())
}
return t.dsType
}