FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
stackrox/central/graphql/generator/codegen/schema.go at master · stackrox/stackrox · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
stackrox
/
stackrox
Public
Notifications
You must be signed in to change notification settings
Fork
191
Star
1.3k
Code
Issues
54
Pull requests
596
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
stackrox
/
central
/
graphql
/
generator
/
codegen
/
schema.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
125 lines (114 loc) · 2.47 KB
Breadcrumbs
stackrox
/
central
/
graphql
/
generator
/
codegen
/
schema.go
Copy path
File metadata and controls
125 lines (114 loc) · 2.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
117
118
119
120
121
122
123
124
125
package
codegen
import
(
"fmt"
"reflect"
"strings"
"unicode"
"github.com/stackrox/rox/pkg/protocompat"
)
type
schemaEntry
struct
{
Data
typeData
ListData
map
[
string
]reflect.
Type
}
func
isListType
(
p
reflect.
Type
)
bool
{
if
p
==
nil
{
return
false
}
name
:=
p
.
Name
()
if
p
.
Kind
()
==
reflect
.
Pointer
{
name
=
p
.
Elem
().
Name
()
}
return
isProto
(
p
)
&&
len
(
name
)
>
4
&&
name
[
0
:
4
]
==
"List"
}
func
makeSchemaEntries
(
data
[]
typeData
) []
schemaEntry
{
var
output
[]
schemaEntry
listRef
:=
make
(
map
[
string
]
map
[
string
]reflect.
Type
)
for
_
,
td
:=
range
data
{
if
isListType
(
td
.
Type
) {
listFields
:=
make
(
map
[
string
]reflect.
Type
)
for
_
,
f
:=
range
td
.
FieldData
{
listFields
[
f
.
Name
]
=
f
.
Type
}
listRef
[
td
.
Name
[
4
:]]
=
listFields
}
}
for
_
,
td
:=
range
data
{
// Skip unexported types.
if
name
:=
td
.
Type
.
Name
();
len
(
name
)
>
0
&&
unicode
.
IsLower
(
rune
(
name
[
0
])) {
continue
}
// Skip scalars and maps -- except for enums.
if
!
isEnum
(
td
.
Type
) {
if
kind
:=
td
.
Type
.
Kind
();
kind
<=
reflect
.
Complex128
||
kind
==
reflect
.
Map
{
continue
}
}
// Skip list types.
if
isListType
(
td
.
Type
) {
continue
}
output
=
append
(
output
,
schemaEntry
{
Data
:
td
,
ListData
:
listRef
[
td
.
Name
],
})
}
return
output
}
func
schemaType
(
fd
fieldData
)
string
{
if
strings
.
ToLower
(
fd
.
Name
)
==
"id"
&&
fd
.
Type
.
Kind
()
==
reflect
.
String
{
return
"ID!"
}
return
schemaExpand
(
fd
.
Type
)
}
func
schemaExpand
(
p
reflect.
Type
)
string
{
switch
p
.
Kind
() {
case
reflect
.
String
:
return
"String!"
case
reflect
.
Int32
:
if
isEnum
(
p
) {
return
p
.
Name
()
+
"!"
}
return
"Int!"
case
reflect
.
Int64
:
return
"Int!"
case
reflect
.
Uint32
:
return
"Int!"
case
reflect
.
Float32
:
return
"Float!"
case
reflect
.
Float64
:
return
"Float!"
case
reflect
.
Bool
:
return
"Boolean!"
case
reflect
.
Slice
:
// Handle []byte (protobuf bytes) as base64-encoded strings
if
p
.
Elem
().
Kind
()
==
reflect
.
Uint8
{
return
"String!"
}
inner
:=
schemaExpand
(
p
.
Elem
())
if
inner
!=
""
{
return
fmt
.
Sprintf
(
"[%s]!"
,
inner
)
}
return
""
case
reflect
.
Map
:
if
p
.
Key
().
Kind
()
==
reflect
.
String
&&
p
.
Elem
().
Kind
()
==
reflect
.
String
{
return
"[Label!]!"
}
case
reflect
.
Pointer
:
if
p
==
protocompat
.
TimestampPtrType
{
return
"Time"
}
elem
:=
p
.
Elem
()
if
elem
.
Kind
()
==
reflect
.
Struct
{
return
elem
.
Name
()
}
inner
:=
schemaExpand
(
elem
)
if
inner
==
""
{
return
""
}
if
strings
.
HasSuffix
(
inner
,
"!"
) {
return
inner
[:
len
(
inner
)
-
1
]
}
return
inner
}
return
""
}
Back
|
FazBrowse Home
|
New Git URL