Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/protoc-gen-go/internal_gengo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,22 @@ func fieldDefaultValue(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, f
}

func fieldJSONTagValue(field *protogen.Field) string {
if field.Desc.JSONName() == "-" {
return "-"
} else if field.Desc.JSONName() == "MUST" {
return string(field.Desc.Name())
}
Comment on lines +759 to +763

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe such a change of semantics would result in this package having incompatible behavior with other language’s protobuf.

Since protocolbuffers are a multi-/intra-language encoding/decoding format, we cannot unilaterally produce such features as you seem to be designing here.

This will need to be implemented by either its own protobuf extension, or seeking to get this semantic accepted into the wider protobuf ecosystem. Until the later is met, this package would not be considering adding this feature.

return string(field.Desc.Name()) + ",omitempty"
}

func fieldFORMTagValue(field *protogen.Field) string {
return string(field.Desc.Name())
}

func fieldURITagValue(field *protogen.Field) string {
return string(field.Desc.Name())
}

func genExtensions(g *protogen.GeneratedFile, f *fileInfo) {
if len(f.allExtensions) == 0 {
return
Expand Down
7 changes: 6 additions & 1 deletion cmd/protoc-gen-go/internal_gengo/opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func opaqueGenMessageField(g *protogen.GeneratedFile, f *fileInfo, message *mess
}
protobufTagValue := fieldProtobufTagValue(field)
jsonTagValue := fieldJSONTagValue(field)
formTagValue := fieldFORMTagValue(field)
uriTagValue := fieldURITagValue(field)
if g.InternalStripForEditionsDiff() {
if field.Desc.ContainingOneof() != nil && field.Desc.ContainingOneof().IsSynthetic() {
protobufTagValue = strings.ReplaceAll(protobufTagValue, ",oneof", "")
Expand All @@ -95,7 +97,10 @@ func opaqueGenMessageField(g *protogen.GeneratedFile, f *fileInfo, message *mess
{"protobuf", protobufTagValue},
}
if !message.isOpaque() {
tags = append(tags, structTags{{"json", jsonTagValue}}...)
tags = append(tags, structTags{
{"json", jsonTagValue},
{"form", formTagValue},
{"uri", uriTagValue}}...)
}
if field.Desc.IsMap() {
keyTagValue := fieldProtobufTagValue(field.Message.Fields[0])
Expand Down