Skip to content

Commit

Permalink
Remove field name decapitalization in the scheme (#34)
Browse files Browse the repository at this point in the history
Problem:

For consistency with DataFabric examples, we make field names start
with lowercase letter. As a result, we convert the first character
of field name in a go struct to lowercase. For example,
MyField -> myField. However, the generated scheme names for fields
like HTTPRoutes look a bit ugly: HTTPRoutes -> hTTPRoutes

Solution:

This is not a hard requirement for Avro scheme, we can use names like
HTTPRoutes just fine.

long? HTTPRoutes = null;

CLOSES -- #33
  • Loading branch information
pleshakov authored Mar 6, 2024
1 parent 1d345b9 commit f5b0474
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
9 changes: 2 additions & 7 deletions cmd/generator/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"go/types"
"io"
"strings"
"text/template"
)

Expand Down Expand Up @@ -42,10 +41,6 @@ func getAvroPrimitiveType(kind types.BasicKind) string {
}
}

func getAvroFieldName(name string) string {
return strings.ToLower(name[:1]) + name[1:]
}

type schemeGen struct {
Namespace string
Protocol string
Expand Down Expand Up @@ -78,15 +73,15 @@ func generateScheme(writer io.Writer, cfg schemeGenConfig) error {
schemeFields = append(schemeFields, schemeField{
Comment: f.docString,
Type: fmt.Sprintf("union {null, array<%s>}", getAvroPrimitiveType(f.fieldType)),
Name: getAvroFieldName(f.name),
Name: f.name,
})
} else if f.embeddedStruct {
createSchemeFields(f.embeddedStructFields)
} else {
schemeFields = append(schemeFields, schemeField{
Comment: f.docString,
Type: getAvroPrimitiveType(f.fieldType) + "?",
Name: getAvroFieldName(f.name),
Name: f.name,
})
}
}
Expand Down
32 changes: 16 additions & 16 deletions cmd/generator/tests/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@


/** SomeString is a string field. */
string? someString = null;
string? SomeString = null;

/** SomeInt is an int64 field. */
long? someInt = null;
long? SomeInt = null;

/** SomeFloat is a float64 field.
More comments. */
double? someFloat = null;
double? SomeFloat = null;

/** SomeBool is a bool field. */
boolean? someBool = null;
boolean? SomeBool = null;

/** SomeStrings is a slice of strings. */
union {null, array<string>} someStrings = null;
union {null, array<string>} SomeStrings = null;

/** SomeInts is a slice of int64. */
union {null, array<long>} someInts = null;
union {null, array<long>} SomeInts = null;

/** SomeFloats is a slice of float64. */
union {null, array<double>} someFloats = null;
union {null, array<double>} SomeFloats = null;

/** SomeBools is a slice of bool. */
union {null, array<boolean>} someBools = null;
union {null, array<boolean>} SomeBools = null;

/** AnotherSomeString is a string field. */
string? anotherSomeString = null;
string? AnotherSomeString = null;

/** AnotherSomeInt is an int64 field. */
long? anotherSomeInt = null;
long? AnotherSomeInt = null;

/** AnotherSomeFloat is a float64 field. */
double? anotherSomeFloat = null;
double? AnotherSomeFloat = null;

/** AnotherSomeBool is a bool field. */
boolean? anotherSomeBool = null;
boolean? AnotherSomeBool = null;

/** AnotherSomeStrings is a slice of strings. */
union {null, array<string>} anotherSomeStrings = null;
union {null, array<string>} AnotherSomeStrings = null;

/** AnotherSomeInts is a slice of int64. */
union {null, array<long>} anotherSomeInts = null;
union {null, array<long>} AnotherSomeInts = null;

/** AnotherSomeFloats is a slice of float64. */
union {null, array<double>} anotherSomeFloats = null;
union {null, array<double>} AnotherSomeFloats = null;

/** AnotherSomeBools is a slice of bool. */
union {null, array<boolean>} anotherSomeBools = null;
union {null, array<boolean>} AnotherSomeBools = null;

}
}

0 comments on commit f5b0474

Please sign in to comment.