From 8dc0d5956391f7e43a217649314f0e2e1a5f0d96 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Tue, 5 Mar 2024 16:22:51 +1100 Subject: [PATCH] fix: lowercase request and response fields should produce an error (#1016) Fixes #848 --- go-runtime/compile/schema.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/go-runtime/compile/schema.go b/go-runtime/compile/schema.go index 1904b1a380..40ca38f2f6 100644 --- a/go-runtime/compile/schema.go +++ b/go-runtime/compile/schema.go @@ -10,6 +10,7 @@ import ( "reflect" "strings" "sync" + "unicode" "golang.org/x/tools/go/ast/astutil" "golang.org/x/tools/go/packages" @@ -417,6 +418,11 @@ func visitStruct(pctx *parseContext, node ast.Node, tnode types.Type) (*schema.D return nil, fmt.Errorf("field %s: %w", f.Name(), err) } + // Check if field is exported + if len(f.Name()) > 0 && unicode.IsLower(rune(f.Name()[0])) { + return nil, fmt.Errorf("params field %s must be exported by starting with an uppercase letter", f.Name()) + } + // Extract the JSON tag and split it to get just the field name tagContent := reflect.StructTag(s.Tag(i)).Get(aliasFieldTag) tagParts := strings.Split(tagContent, ",")