diff --git a/go-runtime/compile/schema.go b/go-runtime/compile/schema.go index c982789af..6c88f8f89 100644 --- a/go-runtime/compile/schema.go +++ b/go-runtime/compile/schema.go @@ -417,11 +417,19 @@ func visitStruct(pctx *parseContext, node ast.Node, tnode types.Type) (*schema.D return nil, fmt.Errorf("field %s: %w", f.Name(), err) } + // 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, ",") + jsonFieldName := "" + if len(tagParts) > 0 { + jsonFieldName = tagParts[0] + } + out.Fields = append(out.Fields, &schema.Field{ Pos: goPosToSchemaPos(node.Pos()), Name: strcase.ToLowerCamel(f.Name()), Type: ft, - JSONAlias: reflect.StructTag(s.Tag(i)).Get(aliasFieldTag), + JSONAlias: jsonFieldName, }) } pctx.module.AddData(out) diff --git a/integration/testdata/go/httpingress/echo.go b/integration/testdata/go/httpingress/echo.go index 6650dbafe..96d028f3c 100644 --- a/integration/testdata/go/httpingress/echo.go +++ b/integration/testdata/go/httpingress/echo.go @@ -11,8 +11,8 @@ import ( ) type GetRequest struct { - UserID string `json:"userId"` - PostID string `json:"postId"` + UserID string `json:"userId,omitempty"` + PostID string `json:"postId,something,else"` } type Nested struct {