Skip to content

Commit

Permalink
fix: lowercase request and response fields should produce an error (#…
Browse files Browse the repository at this point in the history
…1016)

Fixes #848
  • Loading branch information
matt2e authored Mar 5, 2024
1 parent a432d45 commit 8dc0d59
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"reflect"
"strings"
"sync"
"unicode"

"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"
Expand Down Expand Up @@ -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, ",")
Expand Down

0 comments on commit 8dc0d59

Please sign in to comment.