/
model.go
67 lines (56 loc) · 1.32 KB
/
model.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
// Copyright 2021 IBM Corp.
// SPDX-License-Identifier: Apache-2.0
package builder
import "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
type Model struct {
Metadata PageMetadata `yaml:"metadata"`
Groups []*GroupModel `yaml:"groups"`
}
type GroupModel struct {
// Metadata PageMetadata `yaml:"metadata"`
Group string `yaml:"group"`
Version string `yaml:"version"`
Kinds []*KindModel `yaml:"kinds"`
}
type KindModel struct {
// Metadata PageMetadata `yaml:"metadata"`
Name string `yaml:"name"`
Types []*TypeModel
}
type PageMetadata struct {
Title string `yaml:"title"`
Weight int `yaml:"weight"`
Description string `yaml:"description"`
}
type TypeModel struct {
Name string
Key string
ParentKey *string
Description string
IsTopLevel bool
Fields []*FieldModel
}
type FieldModel struct {
Name string
Type string
TypeKey *string
Description string
Required bool
Schema apiextensions.JSONSchemaProps
}
func (m *Model) findGroupModel(group, version string) *GroupModel {
for _, v := range m.Groups {
if group == v.Group && version == v.Version {
return v
}
}
return nil
}
func (m *GroupModel) findKindModel(kind string) *KindModel {
for _, v := range m.Kinds {
if kind == v.Name {
return v
}
}
return nil
}