forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
158 lines (147 loc) · 4.85 KB
/
schema.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package schema
import (
"sort"
"github.com/dafanshu/benthos/v3/internal/bloblang/query"
"github.com/dafanshu/benthos/v3/internal/bundle"
"github.com/dafanshu/benthos/v3/internal/docs"
"github.com/dafanshu/benthos/v3/lib/condition"
"github.com/dafanshu/benthos/v3/lib/config"
)
// Full represents the entirety of the Benthos instances configuration spec and
// all plugins.
type Full struct {
Version string `json:"version"`
Date string `json:"date"`
Config docs.FieldSpecs `json:"config,omitempty"`
Buffers []docs.ComponentSpec `json:"buffers,omitempty"`
Caches []docs.ComponentSpec `json:"caches,omitempty"`
Inputs []docs.ComponentSpec `json:"inputs,omitempty"`
Outputs []docs.ComponentSpec `json:"outputs,omitempty"`
Processors []docs.ComponentSpec `json:"processors,omitempty"`
RateLimits []docs.ComponentSpec `json:"rate-limits,omitempty"`
Metrics []docs.ComponentSpec `json:"metrics,omitempty"`
Tracers []docs.ComponentSpec `json:"tracers,omitempty"`
conditions []string
BloblangFunctions []query.FunctionSpec `json:"bloblang-functions,omitempty"`
BloblangMethods []query.MethodSpec `json:"bloblang-methods,omitempty"`
}
// New walks all registered Benthos components and creates a full schema
// definition of it.
func New(version, date string) Full {
s := Full{
Version: version,
Date: date,
Config: config.Spec(),
Buffers: bundle.AllBuffers.Docs(),
Caches: bundle.AllCaches.Docs(),
Inputs: bundle.AllInputs.Docs(),
Outputs: bundle.AllOutputs.Docs(),
Processors: bundle.AllProcessors.Docs(),
RateLimits: bundle.AllRateLimits.Docs(),
Metrics: bundle.AllMetrics.Docs(),
Tracers: bundle.AllTracers.Docs(),
BloblangFunctions: query.FunctionDocs(),
BloblangMethods: query.MethodDocs(),
}
for t := range condition.Constructors {
s.conditions = append(s.conditions, t)
}
sort.Strings(s.conditions)
return s
}
// Flattened returns a flattened representation of all registered plugin types
// and names.
func (f *Full) Flattened() map[string][]string {
justNames := func(components []docs.ComponentSpec) []string {
names := []string{}
for _, c := range components {
if c.Status != docs.StatusDeprecated {
names = append(names, c.Name)
}
}
return names
}
justNamesBloblFuncs := func(fns []query.FunctionSpec) []string {
names := []string{}
for _, c := range fns {
if c.Status != query.StatusDeprecated {
names = append(names, c.Name)
}
}
return names
}
justNamesBloblMethods := func(fns []query.MethodSpec) []string {
names := []string{}
for _, c := range fns {
if c.Status != query.StatusDeprecated {
names = append(names, c.Name)
}
}
return names
}
return map[string][]string{
"buffers": justNames(f.Buffers),
"caches": justNames(f.Caches),
"inputs": justNames(f.Inputs),
"outputs": justNames(f.Outputs),
"processors": justNames(f.Processors),
"rate-limits": justNames(f.RateLimits),
"metrics": justNames(f.Metrics),
"tracers": justNames(f.Tracers),
"conditions": f.conditions,
"bloblang-functions": justNamesBloblFuncs(f.BloblangFunctions),
"bloblang-methods": justNamesBloblMethods(f.BloblangMethods),
}
}
// Scrub walks the schema and removes all descriptions and other long-form
// documentation, reducing the overall size.
func (f *Full) Scrub() {
scrubFieldSpecs(f.Config)
scrubComponentSpecs(f.Buffers)
scrubComponentSpecs(f.Caches)
scrubComponentSpecs(f.Inputs)
scrubComponentSpecs(f.Outputs)
scrubComponentSpecs(f.Processors)
scrubComponentSpecs(f.RateLimits)
scrubComponentSpecs(f.Metrics)
scrubComponentSpecs(f.Tracers)
for i := range f.BloblangFunctions {
f.BloblangFunctions[i].Description = ""
f.BloblangFunctions[i].Examples = nil
scrubParams(f.BloblangFunctions[i].Params.Definitions)
}
for i := range f.BloblangMethods {
f.BloblangMethods[i].Description = ""
f.BloblangMethods[i].Examples = nil
f.BloblangMethods[i].Categories = nil
scrubParams(f.BloblangMethods[i].Params.Definitions)
}
}
func scrubParams(p []query.ParamDefinition) {
for i := range p {
p[i].Description = ""
}
}
func scrubFieldSpecs(fs []docs.FieldSpec) {
for i := range fs {
fs[i].Description = ""
fs[i].Examples = nil
for j := range fs[i].AnnotatedOptions {
fs[i].AnnotatedOptions[j][1] = ""
}
scrubFieldSpecs(fs[i].Children)
}
}
func scrubFieldSpec(fs *docs.FieldSpec) {
fs.Description = ""
scrubFieldSpecs(fs.Children)
}
func scrubComponentSpecs(cs []docs.ComponentSpec) {
for i := range cs {
cs[i].Description = ""
cs[i].Summary = ""
cs[i].Footnotes = ""
cs[i].Examples = nil
scrubFieldSpec(&cs[i].Config)
}
}