Skip to content

Commit d7a890e

Browse files
authored
Handle 'if' change to '_types.Script' (#16)
In ProcessorBase, the 'if' type changed from string to _types.Script which is a struct. The elasticsearch-specification allows 'if' to also be a string through a special 'shortcutProperty' where when 'if' is defined as a scalar then this means to populate the _types.Script#source field. Rather than drastically change the generated Go types and json-schema this basically overrides the _types.Script as a string. In the future we could consider properly handing the 'shortcutProperty'. Closes #15
1 parent ba82a32 commit d7a890e

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

internal/generator/internal/codegen/generator.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@ import (
3232
"github.com/fatih/camelcase"
3333
)
3434

35-
// override the _builtins from the spec with native Go types.
35+
// override types within the spec with native Go types.
3636
var overrides = map[string]string{
37-
"boolean": "bool",
38-
"double": "float64",
39-
"integer": "int32",
40-
"long": "int64",
37+
"_builtins.boolean": "bool",
38+
"_builtins.double": "float64",
39+
"_builtins.integer": "int32",
40+
"_builtins.long": "int64",
41+
"_types.boolean": "bool",
42+
"_types.double": "float64",
43+
"_types.integer": "int32",
44+
"_types.long": "int64",
45+
46+
// NOTE: This is an override and divergence from the upstream specification.
47+
// It pins the 'if' property of processors, which are defined using
48+
// _types.Script, to be a string type instead of a struct. This is a
49+
// workaround solving issue:
50+
// https://github.com/andrewkroh/go-ingest-node/issues/15.
51+
"_types.Script": "string",
4152
}
4253

4354
// acronyms is a set of acronyms that should be capitalized in identifiers.
@@ -130,7 +141,7 @@ func (b *Generator) BuildCode(w io.Writer, typeSelector func(name, inherits spec
130141
// Add dependencies to the list.
131142
for d := range deps {
132143
// Skip overwritten types.
133-
if _, found := overrides[d.Name]; found {
144+
if _, found := overrides[qualifiedName(d.Namespace, d.Name)]; found {
134145
continue
135146
}
136147

@@ -324,7 +335,7 @@ func (b *Generator) depsOfValue(v *spec.ValueOf, deps map[spec.TypeName]bool) {
324335
func identifier(v *spec.ValueOf) string {
325336
switch {
326337
case v.InstanceOf != nil:
327-
if o := overrides[v.InstanceOf.TypeName.Name]; o != "" {
338+
if o := overrides[qualifiedName(v.InstanceOf.Namespace, v.InstanceOf.TypeName.Name)]; o != "" {
328339
return o
329340
}
330341
return v.InstanceOf.TypeName.Name
@@ -477,3 +488,8 @@ func trimBalanced(s string, c rune) string {
477488
func escapeTagPart(s string) string {
478489
return strings.ReplaceAll(s, ",", `\,`)
479490
}
491+
492+
// qualifiedName returns the combined type namespace and type name.
493+
func qualifiedName(ns, name string) string {
494+
return ns + "." + name
495+
}

0 commit comments

Comments
 (0)