From eb117e7142d56adfde07167bb80e7519ffb2bd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 29 Nov 2023 05:29:42 +0100 Subject: [PATCH] protoc-gen-go: Add JSON tags to oneof values and members Oneof values should include json tags to use proper camelCase name and can be safely omitted when we're handling the interface. --- cmd/protoc-gen-go/internal_gengo/main.go | 2 + .../testdata/comments/comments.pb.go | 4 +- .../testdata/fieldnames/fieldnames.pb.go | 14 +++--- .../testdata/import_public/sub/a.pb.go | 12 ++--- .../issue780_oneof_conflict/test.pb.go | 4 +- .../testdata/proto2/fields.pb.go | 46 +++++++++---------- .../testdata/retention/retention.pb.go | 4 +- internal/descfmt/desc_test.go | 1 + internal/filedesc/desc.go | 1 + .../testprotos/conformance/conformance.pb.go | 30 ++++++------ .../conformance/test_messages_proto2.pb.go | 20 ++++---- .../conformance/test_messages_proto3.pb.go | 22 ++++----- internal/testprotos/irregular/test.pb.go | 6 +-- internal/testprotos/order/order.pb.go | 4 +- internal/testprotos/test/test.pb.go | 34 +++++++------- internal/testprotos/test3/test.pb.go | 20 ++++---- internal/testprotos/textpb2/test.pb.go | 4 +- internal/testprotos/textpb3/test.pb.go | 8 ++-- reflect/protoreflect/type.go | 4 ++ types/known/structpb/struct.pb.go | 14 +++--- 20 files changed, 131 insertions(+), 123 deletions(-) diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go index 8cae43201..ffd49f64c 100644 --- a/cmd/protoc-gen-go/internal_gengo/main.go +++ b/cmd/protoc-gen-go/internal_gengo/main.go @@ -378,6 +378,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie tags := structTags{ {"protobuf_oneof", string(oneof.Desc.Name())}, + {"json", string(oneof.Desc.JSONName()) + ",omitempty"}, } if m.isTracked { tags = append(tags, gotrackTags...) @@ -812,6 +813,7 @@ func genMessageOneofWrapperTypes(g *protogen.GeneratedFile, f *fileInfo, m *mess goType, _ := fieldGoType(g, f, field) tags := structTags{ {"protobuf", fieldProtobufTagValue(field)}, + {"json", string(field.Desc.JSONName())}, } if m.isTracked { tags = append(tags, gotrackTags...) diff --git a/cmd/protoc-gen-go/testdata/comments/comments.pb.go b/cmd/protoc-gen-go/testdata/comments/comments.pb.go index e0e34e4c4..1d12b7d70 100644 --- a/cmd/protoc-gen-go/testdata/comments/comments.pb.go +++ b/cmd/protoc-gen-go/testdata/comments/comments.pb.go @@ -89,7 +89,7 @@ type Message1 struct { // Types that are assignable to Oneof1A: // // *Message1_Oneof1AField1 - Oneof1A isMessage1_Oneof1A `protobuf_oneof:"Oneof1a"` + Oneof1A isMessage1_Oneof1A `protobuf_oneof:"Oneof1a" json:"Oneof1a,omitempty"` } func (x *Message1) Reset() { @@ -151,7 +151,7 @@ type isMessage1_Oneof1A interface { type Message1_Oneof1AField1 struct { // COMMENT: Oneof1AField1.Leading - Oneof1AField1 string `protobuf:"bytes,2,opt,name=Oneof1AField1,oneof"` // COMMENT: Oneof1AField1.Trailing + Oneof1AField1 string `protobuf:"bytes,2,opt,name=Oneof1AField1,oneof" json:"Oneof1AField1"` // COMMENT: Oneof1AField1.Trailing } func (*Message1_Oneof1AField1) isMessage1_Oneof1A() {} diff --git a/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go b/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go index be5326567..4969e84e9 100644 --- a/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go +++ b/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go @@ -47,20 +47,20 @@ type Message struct { // Types that are assignable to OneofConflictA_: // // *Message_OneofConflictA - OneofConflictA_ isMessage_OneofConflictA_ `protobuf_oneof:"oneof_conflict_a"` + OneofConflictA_ isMessage_OneofConflictA_ `protobuf_oneof:"oneof_conflict_a" json:"oneofConflictA,omitempty"` // Oneof that conflicts with its second field: The field is renamed. // // Types that are assignable to OneofConflictB: // // *Message_OneofNoConflict // *Message_OneofConflictB_ - OneofConflictB isMessage_OneofConflictB `protobuf_oneof:"oneof_conflict_b"` + OneofConflictB isMessage_OneofConflictB `protobuf_oneof:"oneof_conflict_b" json:"oneofConflictB,omitempty"` // Oneof with a field name that conflicts with a nested message. // // Types that are assignable to OneofConflictC: // // *Message_OneofMessageConflict_ - OneofConflictC isMessage_OneofConflictC `protobuf_oneof:"oneof_conflict_c"` + OneofConflictC isMessage_OneofConflictC `protobuf_oneof:"oneof_conflict_c" json:"oneofConflictC,omitempty"` } func (x *Message) Reset() { @@ -247,7 +247,7 @@ type isMessage_OneofConflictA_ interface { } type Message_OneofConflictA struct { - OneofConflictA string `protobuf:"bytes,40,opt,name=OneofConflictA,oneof"` + OneofConflictA string `protobuf:"bytes,40,opt,name=OneofConflictA,oneof" json:"OneofConflictA"` } func (*Message_OneofConflictA) isMessage_OneofConflictA_() {} @@ -257,11 +257,11 @@ type isMessage_OneofConflictB interface { } type Message_OneofNoConflict struct { - OneofNoConflict string `protobuf:"bytes,50,opt,name=oneof_no_conflict,json=oneofNoConflict,oneof"` + OneofNoConflict string `protobuf:"bytes,50,opt,name=oneof_no_conflict,json=oneofNoConflict,oneof" json:"oneofNoConflict"` } type Message_OneofConflictB_ struct { - OneofConflictB_ string `protobuf:"bytes,51,opt,name=OneofConflictB,oneof"` + OneofConflictB_ string `protobuf:"bytes,51,opt,name=OneofConflictB,oneof" json:"OneofConflictB"` } func (*Message_OneofNoConflict) isMessage_OneofConflictB() {} @@ -273,7 +273,7 @@ type isMessage_OneofConflictC interface { } type Message_OneofMessageConflict_ struct { - OneofMessageConflict string `protobuf:"bytes,60,opt,name=oneof_message_conflict,json=oneofMessageConflict,oneof"` + OneofMessageConflict string `protobuf:"bytes,60,opt,name=oneof_message_conflict,json=oneofMessageConflict,oneof" json:"oneofMessageConflict"` } func (*Message_OneofMessageConflict_) isMessage_OneofConflictC() {} diff --git a/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go b/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go index 7f83f6d31..39e1d1457 100644 --- a/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go +++ b/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go @@ -194,7 +194,7 @@ type M struct { // // *M_OneofInt32 // *M_OneofInt64 - OneofField isM_OneofField `protobuf_oneof:"oneof_field"` + OneofField isM_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` } // Default values for M fields. @@ -294,11 +294,11 @@ type isM_OneofField interface { } type M_OneofInt32 struct { - OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,oneof"` + OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,oneof" json:"oneofInt32"` } type M_OneofInt64 struct { - OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,oneof"` + OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,oneof" json:"oneofInt64"` } func (*M_OneofInt32) isM_OneofField() {} @@ -314,7 +314,7 @@ type M_Submessage struct { // // *M_Submessage_SubmessageOneofInt32 // *M_Submessage_SubmessageOneofInt64 - SubmessageOneofField isM_Submessage_SubmessageOneofField `protobuf_oneof:"submessage_oneof_field"` + SubmessageOneofField isM_Submessage_SubmessageOneofField `protobuf_oneof:"submessage_oneof_field" json:"submessageOneofField,omitempty"` } func (x *M_Submessage) Reset() { @@ -375,11 +375,11 @@ type isM_Submessage_SubmessageOneofField interface { } type M_Submessage_SubmessageOneofInt32 struct { - SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,oneof"` + SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,oneof" json:"submessageOneofInt32"` } type M_Submessage_SubmessageOneofInt64 struct { - SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,oneof"` + SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,oneof" json:"submessageOneofInt64"` } func (*M_Submessage_SubmessageOneofInt32) isM_Submessage_SubmessageOneofField() {} diff --git a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go index 40c0ada06..800c93538 100644 --- a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go +++ b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go @@ -22,7 +22,7 @@ type Foo struct { // Types that are assignable to Bar: // // *Foo_GetBar - Bar isFoo_Bar `protobuf_oneof:"bar"` + Bar isFoo_Bar `protobuf_oneof:"bar" json:"bar,omitempty"` } func (x *Foo) Reset() { @@ -76,7 +76,7 @@ type isFoo_Bar interface { } type Foo_GetBar struct { - GetBar string `protobuf:"bytes,1,opt,name=get_bar,json=getBar,oneof"` + GetBar string `protobuf:"bytes,1,opt,name=get_bar,json=getBar,oneof" json:"getBar"` } func (*Foo_GetBar) isFoo_Bar() {} diff --git a/cmd/protoc-gen-go/testdata/proto2/fields.pb.go b/cmd/protoc-gen-go/testdata/proto2/fields.pb.go index ee9546a43..43271a161 100644 --- a/cmd/protoc-gen-go/testdata/proto2/fields.pb.go +++ b/cmd/protoc-gen-go/testdata/proto2/fields.pb.go @@ -178,12 +178,12 @@ type FieldTestMessage struct { // *FieldTestMessage_Oneof_Message // *FieldTestMessage_Oneofgroup // *FieldTestMessage_OneofLargestTag - OneofField isFieldTestMessage_OneofField `protobuf_oneof:"oneof_field"` + OneofField isFieldTestMessage_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` // Types that are assignable to OneofTwo: // // *FieldTestMessage_OneofTwo_1 // *FieldTestMessage_OneofTwo_2 - OneofTwo isFieldTestMessage_OneofTwo `protobuf_oneof:"oneof_two"` + OneofTwo isFieldTestMessage_OneofTwo `protobuf_oneof:"oneof_two" json:"oneofTwo,omitempty"` } // Default values for FieldTestMessage fields. @@ -983,79 +983,79 @@ type isFieldTestMessage_OneofField interface { } type FieldTestMessage_OneofBool struct { - OneofBool bool `protobuf:"varint,601,opt,name=oneof_bool,json=oneofBool,oneof"` + OneofBool bool `protobuf:"varint,601,opt,name=oneof_bool,json=oneofBool,oneof" json:"oneofBool"` } type FieldTestMessage_OneofEnum struct { - OneofEnum FieldTestMessage_Enum `protobuf:"varint,602,opt,name=oneof_enum,json=oneofEnum,enum=goproto.protoc.proto2.FieldTestMessage_Enum,oneof"` + OneofEnum FieldTestMessage_Enum `protobuf:"varint,602,opt,name=oneof_enum,json=oneofEnum,enum=goproto.protoc.proto2.FieldTestMessage_Enum,oneof" json:"oneofEnum"` } type FieldTestMessage_OneofInt32 struct { - OneofInt32 int32 `protobuf:"varint,603,opt,name=oneof_int32,json=oneofInt32,oneof"` + OneofInt32 int32 `protobuf:"varint,603,opt,name=oneof_int32,json=oneofInt32,oneof" json:"oneofInt32"` } type FieldTestMessage_OneofSint32 struct { - OneofSint32 int32 `protobuf:"zigzag32,604,opt,name=oneof_sint32,json=oneofSint32,oneof"` + OneofSint32 int32 `protobuf:"zigzag32,604,opt,name=oneof_sint32,json=oneofSint32,oneof" json:"oneofSint32"` } type FieldTestMessage_OneofUint32 struct { - OneofUint32 uint32 `protobuf:"varint,605,opt,name=oneof_uint32,json=oneofUint32,oneof"` + OneofUint32 uint32 `protobuf:"varint,605,opt,name=oneof_uint32,json=oneofUint32,oneof" json:"oneofUint32"` } type FieldTestMessage_OneofInt64 struct { - OneofInt64 int64 `protobuf:"varint,606,opt,name=oneof_int64,json=oneofInt64,oneof"` + OneofInt64 int64 `protobuf:"varint,606,opt,name=oneof_int64,json=oneofInt64,oneof" json:"oneofInt64"` } type FieldTestMessage_OneofSint64 struct { - OneofSint64 int64 `protobuf:"zigzag64,607,opt,name=oneof_sint64,json=oneofSint64,oneof"` + OneofSint64 int64 `protobuf:"zigzag64,607,opt,name=oneof_sint64,json=oneofSint64,oneof" json:"oneofSint64"` } type FieldTestMessage_OneofUint64 struct { - OneofUint64 uint64 `protobuf:"varint,608,opt,name=oneof_uint64,json=oneofUint64,oneof"` + OneofUint64 uint64 `protobuf:"varint,608,opt,name=oneof_uint64,json=oneofUint64,oneof" json:"oneofUint64"` } type FieldTestMessage_OneofSfixed32 struct { - OneofSfixed32 int32 `protobuf:"fixed32,609,opt,name=oneof_sfixed32,json=oneofSfixed32,oneof"` + OneofSfixed32 int32 `protobuf:"fixed32,609,opt,name=oneof_sfixed32,json=oneofSfixed32,oneof" json:"oneofSfixed32"` } type FieldTestMessage_OneofFixed32 struct { - OneofFixed32 uint32 `protobuf:"fixed32,610,opt,name=oneof_fixed32,json=oneofFixed32,oneof"` + OneofFixed32 uint32 `protobuf:"fixed32,610,opt,name=oneof_fixed32,json=oneofFixed32,oneof" json:"oneofFixed32"` } type FieldTestMessage_OneofFloat struct { - OneofFloat float32 `protobuf:"fixed32,611,opt,name=oneof_float,json=oneofFloat,oneof"` + OneofFloat float32 `protobuf:"fixed32,611,opt,name=oneof_float,json=oneofFloat,oneof" json:"oneofFloat"` } type FieldTestMessage_OneofSfixed64 struct { - OneofSfixed64 int64 `protobuf:"fixed64,612,opt,name=oneof_sfixed64,json=oneofSfixed64,oneof"` + OneofSfixed64 int64 `protobuf:"fixed64,612,opt,name=oneof_sfixed64,json=oneofSfixed64,oneof" json:"oneofSfixed64"` } type FieldTestMessage_OneofFixed64 struct { - OneofFixed64 uint64 `protobuf:"fixed64,613,opt,name=oneof_fixed64,json=oneofFixed64,oneof"` + OneofFixed64 uint64 `protobuf:"fixed64,613,opt,name=oneof_fixed64,json=oneofFixed64,oneof" json:"oneofFixed64"` } type FieldTestMessage_OneofDouble struct { - OneofDouble float64 `protobuf:"fixed64,614,opt,name=oneof_double,json=oneofDouble,oneof"` + OneofDouble float64 `protobuf:"fixed64,614,opt,name=oneof_double,json=oneofDouble,oneof" json:"oneofDouble"` } type FieldTestMessage_OneofString struct { - OneofString string `protobuf:"bytes,615,opt,name=oneof_string,json=oneofString,oneof"` + OneofString string `protobuf:"bytes,615,opt,name=oneof_string,json=oneofString,oneof" json:"oneofString"` } type FieldTestMessage_OneofBytes struct { - OneofBytes []byte `protobuf:"bytes,616,opt,name=oneof_bytes,json=oneofBytes,oneof"` + OneofBytes []byte `protobuf:"bytes,616,opt,name=oneof_bytes,json=oneofBytes,oneof" json:"oneofBytes"` } type FieldTestMessage_Oneof_Message struct { - Oneof_Message *FieldTestMessage_Message `protobuf:"bytes,617,opt,name=oneof_Message,json=oneofMessage,oneof"` + Oneof_Message *FieldTestMessage_Message `protobuf:"bytes,617,opt,name=oneof_Message,json=oneofMessage,oneof" json:"oneofMessage"` } type FieldTestMessage_Oneofgroup struct { - Oneofgroup *FieldTestMessage_OneofGroup `protobuf:"group,618,opt,name=OneofGroup,json=oneofgroup,oneof"` + Oneofgroup *FieldTestMessage_OneofGroup `protobuf:"group,618,opt,name=OneofGroup,json=oneofgroup,oneof" json:"oneofgroup"` } type FieldTestMessage_OneofLargestTag struct { - OneofLargestTag int32 `protobuf:"varint,536870911,opt,name=oneof_largest_tag,json=oneofLargestTag,oneof"` + OneofLargestTag int32 `protobuf:"varint,536870911,opt,name=oneof_largest_tag,json=oneofLargestTag,oneof" json:"oneofLargestTag"` } func (*FieldTestMessage_OneofBool) isFieldTestMessage_OneofField() {} @@ -1101,11 +1101,11 @@ type isFieldTestMessage_OneofTwo interface { } type FieldTestMessage_OneofTwo_1 struct { - OneofTwo_1 int32 `protobuf:"varint,700,opt,name=oneof_two_1,json=oneofTwo1,oneof"` + OneofTwo_1 int32 `protobuf:"varint,700,opt,name=oneof_two_1,json=oneofTwo1,oneof" json:"oneofTwo1"` } type FieldTestMessage_OneofTwo_2 struct { - OneofTwo_2 int64 `protobuf:"varint,701,opt,name=oneof_two_2,json=oneofTwo2,oneof"` + OneofTwo_2 int64 `protobuf:"varint,701,opt,name=oneof_two_2,json=oneofTwo2,oneof" json:"oneofTwo2"` } func (*FieldTestMessage_OneofTwo_1) isFieldTestMessage_OneofTwo() {} diff --git a/cmd/protoc-gen-go/testdata/retention/retention.pb.go b/cmd/protoc-gen-go/testdata/retention/retention.pb.go index f9624b783..2a66424ae 100755 --- a/cmd/protoc-gen-go/testdata/retention/retention.pb.go +++ b/cmd/protoc-gen-go/testdata/retention/retention.pb.go @@ -170,7 +170,7 @@ type TopLevelMessage struct { // Types that are assignable to O: // // *TopLevelMessage_I - O isTopLevelMessage_O `protobuf_oneof:"o"` + O isTopLevelMessage_O `protobuf_oneof:"o" json:"o,omitempty"` } func (x *TopLevelMessage) Reset() { @@ -231,7 +231,7 @@ type isTopLevelMessage_O interface { } type TopLevelMessage_I struct { - I int64 `protobuf:"varint,2,opt,name=i,oneof"` + I int64 `protobuf:"varint,2,opt,name=i,oneof" json:"i"` } func (*TopLevelMessage_I) isTopLevelMessage_O() {} diff --git a/internal/descfmt/desc_test.go b/internal/descfmt/desc_test.go index 549f3b580..649dcdec5 100644 --- a/internal/descfmt/desc_test.go +++ b/internal/descfmt/desc_test.go @@ -23,6 +23,7 @@ func TestDescriptorAccessors(t *testing.T) { "Syntax": true, "Name": true, "FullName": true, + "JSONName": true, "IsPlaceholder": true, "Options": true, "ProtoInternal": true, diff --git a/internal/filedesc/desc.go b/internal/filedesc/desc.go index 7c3689bae..3e282db5a 100644 --- a/internal/filedesc/desc.go +++ b/internal/filedesc/desc.go @@ -351,6 +351,7 @@ func (od *Oneof) Options() protoreflect.ProtoMessage { func (od *Oneof) Fields() protoreflect.FieldDescriptors { return &od.L1.Fields } func (od *Oneof) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, od) } func (od *Oneof) ProtoType(protoreflect.OneofDescriptor) {} +func (od *Oneof) JSONName() string { return strs.JSONCamelCase(string(od.Name())) } type ( Extension struct { diff --git a/internal/testprotos/conformance/conformance.pb.go b/internal/testprotos/conformance/conformance.pb.go index 4852b90b4..bacbb1392 100644 --- a/internal/testprotos/conformance/conformance.pb.go +++ b/internal/testprotos/conformance/conformance.pb.go @@ -209,7 +209,7 @@ type ConformanceRequest struct { // *ConformanceRequest_JsonPayload // *ConformanceRequest_JspbPayload // *ConformanceRequest_TextPayload - Payload isConformanceRequest_Payload `protobuf_oneof:"payload"` + Payload isConformanceRequest_Payload `protobuf_oneof:"payload" json:"payload,omitempty"` // Which format should the testee serialize its message to? RequestedOutputFormat WireFormat `protobuf:"varint,3,opt,name=requested_output_format,json=requestedOutputFormat,proto3,enum=conformance.WireFormat" json:"requested_output_format,omitempty"` // The full name for the test message to use; for the moment, either: @@ -334,20 +334,20 @@ type isConformanceRequest_Payload interface { } type ConformanceRequest_ProtobufPayload struct { - ProtobufPayload []byte `protobuf:"bytes,1,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"` + ProtobufPayload []byte `protobuf:"bytes,1,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof" json:"protobufPayload"` } type ConformanceRequest_JsonPayload struct { - JsonPayload string `protobuf:"bytes,2,opt,name=json_payload,json=jsonPayload,proto3,oneof"` + JsonPayload string `protobuf:"bytes,2,opt,name=json_payload,json=jsonPayload,proto3,oneof" json:"jsonPayload"` } type ConformanceRequest_JspbPayload struct { // Only used inside Google. Opensource testees just skip it. - JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof"` + JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof" json:"jspbPayload"` } type ConformanceRequest_TextPayload struct { - TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof"` + TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof" json:"textPayload"` } func (*ConformanceRequest_ProtobufPayload) isConformanceRequest_Payload() {} @@ -375,7 +375,7 @@ type ConformanceResponse struct { // *ConformanceResponse_Skipped // *ConformanceResponse_JspbPayload // *ConformanceResponse_TextPayload - Result isConformanceResponse_Result `protobuf_oneof:"result"` + Result isConformanceResponse_Result `protobuf_oneof:"result" json:"result,omitempty"` } func (x *ConformanceResponse) Reset() { @@ -490,59 +490,59 @@ type ConformanceResponse_ParseError struct { // // Setting this string does not necessarily mean the testee failed the // test. Some of the test cases are intentionally invalid input. - ParseError string `protobuf:"bytes,1,opt,name=parse_error,json=parseError,proto3,oneof"` + ParseError string `protobuf:"bytes,1,opt,name=parse_error,json=parseError,proto3,oneof" json:"parseError"` } type ConformanceResponse_SerializeError struct { // If the input was successfully parsed but errors occurred when // serializing it to the requested output format, set the error message in // this field. - SerializeError string `protobuf:"bytes,6,opt,name=serialize_error,json=serializeError,proto3,oneof"` + SerializeError string `protobuf:"bytes,6,opt,name=serialize_error,json=serializeError,proto3,oneof" json:"serializeError"` } type ConformanceResponse_TimeoutError struct { // This should be set if the test program timed out. The string should // provide more information about what the child process was doing when it // was killed. - TimeoutError string `protobuf:"bytes,9,opt,name=timeout_error,json=timeoutError,proto3,oneof"` + TimeoutError string `protobuf:"bytes,9,opt,name=timeout_error,json=timeoutError,proto3,oneof" json:"timeoutError"` } type ConformanceResponse_RuntimeError struct { // This should be set if some other error occurred. This will always // indicate that the test failed. The string can provide more information // about the failure. - RuntimeError string `protobuf:"bytes,2,opt,name=runtime_error,json=runtimeError,proto3,oneof"` + RuntimeError string `protobuf:"bytes,2,opt,name=runtime_error,json=runtimeError,proto3,oneof" json:"runtimeError"` } type ConformanceResponse_ProtobufPayload struct { // If the input was successfully parsed and the requested output was // protobuf, serialize it to protobuf and set it in this field. - ProtobufPayload []byte `protobuf:"bytes,3,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"` + ProtobufPayload []byte `protobuf:"bytes,3,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof" json:"protobufPayload"` } type ConformanceResponse_JsonPayload struct { // If the input was successfully parsed and the requested output was JSON, // serialize to JSON and set it in this field. - JsonPayload string `protobuf:"bytes,4,opt,name=json_payload,json=jsonPayload,proto3,oneof"` + JsonPayload string `protobuf:"bytes,4,opt,name=json_payload,json=jsonPayload,proto3,oneof" json:"jsonPayload"` } type ConformanceResponse_Skipped struct { // For when the testee skipped the test, likely because a certain feature // wasn't supported, like JSON input/output. - Skipped string `protobuf:"bytes,5,opt,name=skipped,proto3,oneof"` + Skipped string `protobuf:"bytes,5,opt,name=skipped,proto3,oneof" json:"skipped"` } type ConformanceResponse_JspbPayload struct { // If the input was successfully parsed and the requested output was JSPB, // serialize to JSPB and set it in this field. JSPB is only used inside // Google. Opensource testees can just skip it. - JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof"` + JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof" json:"jspbPayload"` } type ConformanceResponse_TextPayload struct { // If the input was successfully parsed and the requested output was // TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field. - TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof"` + TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof" json:"textPayload"` } func (*ConformanceResponse_ParseError) isConformanceResponse_Result() {} diff --git a/internal/testprotos/conformance/test_messages_proto2.pb.go b/internal/testprotos/conformance/test_messages_proto2.pb.go index 3ca5a6486..60558b4f7 100644 --- a/internal/testprotos/conformance/test_messages_proto2.pb.go +++ b/internal/testprotos/conformance/test_messages_proto2.pb.go @@ -382,7 +382,7 @@ type TestAllTypesProto2 struct { // *TestAllTypesProto2_OneofFloat // *TestAllTypesProto2_OneofDouble // *TestAllTypesProto2_OneofEnum - OneofField isTestAllTypesProto2_OneofField `protobuf_oneof:"oneof_field"` + OneofField isTestAllTypesProto2_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` Data *TestAllTypesProto2_Data `protobuf:"group,201,opt,name=Data,json=data" json:"data,omitempty"` // default values DefaultInt32 *int32 `protobuf:"varint,241,opt,name=default_int32,json=defaultInt32,def=-123456789" json:"default_int32,omitempty"` @@ -1420,39 +1420,39 @@ type isTestAllTypesProto2_OneofField interface { } type TestAllTypesProto2_OneofUint32 struct { - OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,oneof"` + OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,oneof" json:"oneofUint32"` } type TestAllTypesProto2_OneofNestedMessage struct { - OneofNestedMessage *TestAllTypesProto2_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof"` + OneofNestedMessage *TestAllTypesProto2_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof" json:"oneofNestedMessage"` } type TestAllTypesProto2_OneofString struct { - OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,oneof"` + OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,oneof" json:"oneofString"` } type TestAllTypesProto2_OneofBytes struct { - OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,oneof"` + OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,oneof" json:"oneofBytes"` } type TestAllTypesProto2_OneofBool struct { - OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,oneof"` + OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,oneof" json:"oneofBool"` } type TestAllTypesProto2_OneofUint64 struct { - OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,oneof"` + OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,oneof" json:"oneofUint64"` } type TestAllTypesProto2_OneofFloat struct { - OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,oneof"` + OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,oneof" json:"oneofFloat"` } type TestAllTypesProto2_OneofDouble struct { - OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,oneof"` + OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,oneof" json:"oneofDouble"` } type TestAllTypesProto2_OneofEnum struct { - OneofEnum TestAllTypesProto2_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,enum=protobuf_test_messages.proto2.TestAllTypesProto2_NestedEnum,oneof"` + OneofEnum TestAllTypesProto2_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,enum=protobuf_test_messages.proto2.TestAllTypesProto2_NestedEnum,oneof" json:"oneofEnum"` } func (*TestAllTypesProto2_OneofUint32) isTestAllTypesProto2_OneofField() {} diff --git a/internal/testprotos/conformance/test_messages_proto3.pb.go b/internal/testprotos/conformance/test_messages_proto3.pb.go index 56b799ecc..728c04522 100644 --- a/internal/testprotos/conformance/test_messages_proto3.pb.go +++ b/internal/testprotos/conformance/test_messages_proto3.pb.go @@ -355,7 +355,7 @@ type TestAllTypesProto3 struct { // *TestAllTypesProto3_OneofDouble // *TestAllTypesProto3_OneofEnum // *TestAllTypesProto3_OneofNullValue - OneofField isTestAllTypesProto3_OneofField `protobuf_oneof:"oneof_field"` + OneofField isTestAllTypesProto3_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` // Well-known types OptionalBoolWrapper *wrapperspb.BoolValue `protobuf:"bytes,201,opt,name=optional_bool_wrapper,json=optionalBoolWrapper,proto3" json:"optional_bool_wrapper,omitempty"` OptionalInt32Wrapper *wrapperspb.Int32Value `protobuf:"bytes,202,opt,name=optional_int32_wrapper,json=optionalInt32Wrapper,proto3" json:"optional_int32_wrapper,omitempty"` @@ -1512,43 +1512,43 @@ type isTestAllTypesProto3_OneofField interface { } type TestAllTypesProto3_OneofUint32 struct { - OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof"` + OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof" json:"oneofUint32"` } type TestAllTypesProto3_OneofNestedMessage struct { - OneofNestedMessage *TestAllTypesProto3_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,proto3,oneof"` + OneofNestedMessage *TestAllTypesProto3_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,proto3,oneof" json:"oneofNestedMessage"` } type TestAllTypesProto3_OneofString struct { - OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof"` + OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof" json:"oneofString"` } type TestAllTypesProto3_OneofBytes struct { - OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof"` + OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof" json:"oneofBytes"` } type TestAllTypesProto3_OneofBool struct { - OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof"` + OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof" json:"oneofBool"` } type TestAllTypesProto3_OneofUint64 struct { - OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof"` + OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof" json:"oneofUint64"` } type TestAllTypesProto3_OneofFloat struct { - OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof"` + OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof" json:"oneofFloat"` } type TestAllTypesProto3_OneofDouble struct { - OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof"` + OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof" json:"oneofDouble"` } type TestAllTypesProto3_OneofEnum struct { - OneofEnum TestAllTypesProto3_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=protobuf_test_messages.proto3.TestAllTypesProto3_NestedEnum,oneof"` + OneofEnum TestAllTypesProto3_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=protobuf_test_messages.proto3.TestAllTypesProto3_NestedEnum,oneof" json:"oneofEnum"` } type TestAllTypesProto3_OneofNullValue struct { - OneofNullValue structpb.NullValue `protobuf:"varint,120,opt,name=oneof_null_value,json=oneofNullValue,proto3,enum=google.protobuf.NullValue,oneof"` + OneofNullValue structpb.NullValue `protobuf:"varint,120,opt,name=oneof_null_value,json=oneofNullValue,proto3,enum=google.protobuf.NullValue,oneof" json:"oneofNullValue"` } func (*TestAllTypesProto3_OneofUint32) isTestAllTypesProto3_OneofField() {} diff --git a/internal/testprotos/irregular/test.pb.go b/internal/testprotos/irregular/test.pb.go index f375c48fc..3a9ad6354 100644 --- a/internal/testprotos/irregular/test.pb.go +++ b/internal/testprotos/irregular/test.pb.go @@ -31,7 +31,7 @@ type Message struct { // // *Message_OneofMessage // *Message_OneofAberrantMessage - Union isMessage_Union `protobuf_oneof:"union"` + Union isMessage_Union `protobuf_oneof:"union" json:"union,omitempty"` OptionalAberrantMessage *AberrantMessage `protobuf:"bytes,7,opt,name=optional_aberrant_message,json=optionalAberrantMessage" json:"optional_aberrant_message,omitempty"` RepeatedAberrantMessage []*AberrantMessage `protobuf:"bytes,8,rep,name=repeated_aberrant_message,json=repeatedAberrantMessage" json:"repeated_aberrant_message,omitempty"` RequiredAberrantMessage *AberrantMessage `protobuf:"bytes,9,req,name=required_aberrant_message,json=requiredAberrantMessage" json:"required_aberrant_message,omitempty"` @@ -152,11 +152,11 @@ type isMessage_Union interface { } type Message_OneofMessage struct { - OneofMessage *IrregularMessage `protobuf:"bytes,5,opt,name=oneof_message,json=oneofMessage,oneof"` + OneofMessage *IrregularMessage `protobuf:"bytes,5,opt,name=oneof_message,json=oneofMessage,oneof" json:"oneofMessage"` } type Message_OneofAberrantMessage struct { - OneofAberrantMessage *AberrantMessage `protobuf:"bytes,6,opt,name=oneof_aberrant_message,json=oneofAberrantMessage,oneof"` + OneofAberrantMessage *AberrantMessage `protobuf:"bytes,6,opt,name=oneof_aberrant_message,json=oneofAberrantMessage,oneof" json:"oneofAberrantMessage"` } func (*Message_OneofMessage) isMessage_Union() {} diff --git a/internal/testprotos/order/order.pb.go b/internal/testprotos/order/order.pb.go index b62ef9519..db5d87659 100644 --- a/internal/testprotos/order/order.pb.go +++ b/internal/testprotos/order/order.pb.go @@ -27,7 +27,7 @@ type Message struct { // Types that are assignable to Oneof_1: // // *Message_Field_10 - Oneof_1 isMessage_Oneof_1 `protobuf_oneof:"oneof_1"` + Oneof_1 isMessage_Oneof_1 `protobuf_oneof:"oneof_1" json:"oneof1,omitempty"` Field_20 *string `protobuf:"bytes,20,opt,name=field_20,json=field20" json:"field_20,omitempty"` } @@ -103,7 +103,7 @@ type isMessage_Oneof_1 interface { } type Message_Field_10 struct { - Field_10 string `protobuf:"bytes,10,opt,name=field_10,json=field10,oneof"` + Field_10 string `protobuf:"bytes,10,opt,name=field_10,json=field10,oneof" json:"field10"` } func (*Message_Field_10) isMessage_Oneof_1() {} diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go index a828a515d..28f114855 100644 --- a/internal/testprotos/test/test.pb.go +++ b/internal/testprotos/test/test.pb.go @@ -341,13 +341,13 @@ type TestAllTypes struct { // *TestAllTypes_OneofDouble // *TestAllTypes_OneofEnum // *TestAllTypes_Oneofgroup - OneofField isTestAllTypes_OneofField `protobuf_oneof:"oneof_field"` + OneofField isTestAllTypes_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` // A oneof with exactly one field. // // Types that are assignable to OneofOptional: // // *TestAllTypes_OneofOptionalUint32 - OneofOptional isTestAllTypes_OneofOptional `protobuf_oneof:"oneof_optional"` + OneofOptional isTestAllTypes_OneofOptional `protobuf_oneof:"oneof_optional" json:"oneofOptional,omitempty"` } // Default values for TestAllTypes fields. @@ -1049,43 +1049,43 @@ type isTestAllTypes_OneofField interface { } type TestAllTypes_OneofUint32 struct { - OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,oneof"` + OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,oneof" json:"oneofUint32"` } type TestAllTypes_OneofNestedMessage struct { - OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof"` + OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof" json:"oneofNestedMessage"` } type TestAllTypes_OneofString struct { - OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,oneof"` + OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,oneof" json:"oneofString"` } type TestAllTypes_OneofBytes struct { - OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,oneof"` + OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,oneof" json:"oneofBytes"` } type TestAllTypes_OneofBool struct { - OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,oneof"` + OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,oneof" json:"oneofBool"` } type TestAllTypes_OneofUint64 struct { - OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,oneof"` + OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,oneof" json:"oneofUint64"` } type TestAllTypes_OneofFloat struct { - OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,oneof"` + OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,oneof" json:"oneofFloat"` } type TestAllTypes_OneofDouble struct { - OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,oneof"` + OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,oneof" json:"oneofDouble"` } type TestAllTypes_OneofEnum struct { - OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,enum=goproto.proto.test.TestAllTypes_NestedEnum,oneof"` + OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,enum=goproto.proto.test.TestAllTypes_NestedEnum,oneof" json:"oneofEnum"` } type TestAllTypes_Oneofgroup struct { - Oneofgroup *TestAllTypes_OneofGroup `protobuf:"group,121,opt,name=OneofGroup,json=oneofgroup,oneof"` + Oneofgroup *TestAllTypes_OneofGroup `protobuf:"group,121,opt,name=OneofGroup,json=oneofgroup,oneof" json:"oneofgroup"` } func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {} @@ -1113,7 +1113,7 @@ type isTestAllTypes_OneofOptional interface { } type TestAllTypes_OneofOptionalUint32 struct { - OneofOptionalUint32 uint32 `protobuf:"varint,120,opt,name=oneof_optional_uint32,json=oneofOptionalUint32,oneof"` + OneofOptionalUint32 uint32 `protobuf:"varint,120,opt,name=oneof_optional_uint32,json=oneofOptionalUint32,oneof" json:"oneofOptionalUint32"` } func (*TestAllTypes_OneofOptionalUint32) isTestAllTypes_OneofOptional() {} @@ -1129,7 +1129,7 @@ type TestDeprecatedMessage struct { // Types that are assignable to DeprecatedOneof: // // *TestDeprecatedMessage_DeprecatedOneofField - DeprecatedOneof isTestDeprecatedMessage_DeprecatedOneof `protobuf_oneof:"deprecated_oneof"` + DeprecatedOneof isTestDeprecatedMessage_DeprecatedOneof `protobuf_oneof:"deprecated_oneof" json:"deprecatedOneof,omitempty"` } func (x *TestDeprecatedMessage) Reset() { @@ -1193,7 +1193,7 @@ type isTestDeprecatedMessage_DeprecatedOneof interface { type TestDeprecatedMessage_DeprecatedOneofField struct { // Deprecated: Marked as deprecated in internal/testprotos/test/test.proto. - DeprecatedOneofField int32 `protobuf:"varint,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,oneof"` + DeprecatedOneofField int32 `protobuf:"varint,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,oneof" json:"deprecatedOneofField"` } func (*TestDeprecatedMessage_DeprecatedOneofField) isTestDeprecatedMessage_DeprecatedOneof() {} @@ -1544,7 +1544,7 @@ type TestRequiredForeign struct { // Types that are assignable to OneofField: // // *TestRequiredForeign_OneofMessage - OneofField isTestRequiredForeign_OneofField `protobuf_oneof:"oneof_field"` + OneofField isTestRequiredForeign_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` } func (x *TestRequiredForeign) Reset() { @@ -1619,7 +1619,7 @@ type isTestRequiredForeign_OneofField interface { } type TestRequiredForeign_OneofMessage struct { - OneofMessage *TestRequired `protobuf:"bytes,4,opt,name=oneof_message,json=oneofMessage,oneof"` + OneofMessage *TestRequired `protobuf:"bytes,4,opt,name=oneof_message,json=oneofMessage,oneof" json:"oneofMessage"` } func (*TestRequiredForeign_OneofMessage) isTestRequiredForeign_OneofField() {} diff --git a/internal/testprotos/test3/test.pb.go b/internal/testprotos/test3/test.pb.go index d2ff0bf28..55af7607f 100644 --- a/internal/testprotos/test3/test.pb.go +++ b/internal/testprotos/test3/test.pb.go @@ -214,7 +214,7 @@ type TestAllTypes struct { // *TestAllTypes_OneofFloat // *TestAllTypes_OneofDouble // *TestAllTypes_OneofEnum - OneofField isTestAllTypes_OneofField `protobuf_oneof:"oneof_field"` + OneofField isTestAllTypes_OneofField `protobuf_oneof:"oneof_field" json:"oneofField,omitempty"` } func (x *TestAllTypes) Reset() { @@ -884,39 +884,39 @@ type isTestAllTypes_OneofField interface { } type TestAllTypes_OneofUint32 struct { - OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof"` + OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof" json:"oneofUint32"` } type TestAllTypes_OneofNestedMessage struct { - OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,proto3,oneof"` + OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,proto3,oneof" json:"oneofNestedMessage"` } type TestAllTypes_OneofString struct { - OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof"` + OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof" json:"oneofString"` } type TestAllTypes_OneofBytes struct { - OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof"` + OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof" json:"oneofBytes"` } type TestAllTypes_OneofBool struct { - OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof"` + OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof" json:"oneofBool"` } type TestAllTypes_OneofUint64 struct { - OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof"` + OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof" json:"oneofUint64"` } type TestAllTypes_OneofFloat struct { - OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof"` + OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof" json:"oneofFloat"` } type TestAllTypes_OneofDouble struct { - OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof"` + OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof" json:"oneofDouble"` } type TestAllTypes_OneofEnum struct { - OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=goproto.proto.test3.TestAllTypes_NestedEnum,oneof"` + OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=goproto.proto.test3.TestAllTypes_NestedEnum,oneof" json:"oneofEnum"` } func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {} diff --git a/internal/testprotos/textpb2/test.pb.go b/internal/testprotos/textpb2/test.pb.go index ec2547185..562fd0388 100644 --- a/internal/testprotos/textpb2/test.pb.go +++ b/internal/testprotos/textpb2/test.pb.go @@ -871,7 +871,7 @@ type IndirectRequired struct { // Types that are assignable to Union: // // *IndirectRequired_OneofNested - Union isIndirectRequired_Union `protobuf_oneof:"union"` + Union isIndirectRequired_Union `protobuf_oneof:"union" json:"union,omitempty"` } func (x *IndirectRequired) Reset() { @@ -946,7 +946,7 @@ type isIndirectRequired_Union interface { } type IndirectRequired_OneofNested struct { - OneofNested *NestedWithRequired `protobuf:"bytes,4,opt,name=oneof_nested,json=oneofNested,oneof"` + OneofNested *NestedWithRequired `protobuf:"bytes,4,opt,name=oneof_nested,json=oneofNested,oneof" json:"oneofNested"` } func (*IndirectRequired_OneofNested) isIndirectRequired_Union() {} diff --git a/internal/testprotos/textpb3/test.pb.go b/internal/testprotos/textpb3/test.pb.go index be8034c5b..18ecafd9b 100644 --- a/internal/testprotos/textpb3/test.pb.go +++ b/internal/testprotos/textpb3/test.pb.go @@ -690,7 +690,7 @@ type Oneofs struct { // *Oneofs_OneofEnum // *Oneofs_OneofString // *Oneofs_OneofNested - Union isOneofs_Union `protobuf_oneof:"union"` + Union isOneofs_Union `protobuf_oneof:"union" json:"union,omitempty"` } func (x *Oneofs) Reset() { @@ -758,15 +758,15 @@ type isOneofs_Union interface { } type Oneofs_OneofEnum struct { - OneofEnum Enum `protobuf:"varint,1,opt,name=oneof_enum,json=oneofEnum,proto3,enum=pb3.Enum,oneof"` + OneofEnum Enum `protobuf:"varint,1,opt,name=oneof_enum,json=oneofEnum,proto3,enum=pb3.Enum,oneof" json:"oneofEnum"` } type Oneofs_OneofString struct { - OneofString string `protobuf:"bytes,2,opt,name=oneof_string,json=oneofString,proto3,oneof"` + OneofString string `protobuf:"bytes,2,opt,name=oneof_string,json=oneofString,proto3,oneof" json:"oneofString"` } type Oneofs_OneofNested struct { - OneofNested *Nested `protobuf:"bytes,3,opt,name=oneof_nested,json=oneofNested,proto3,oneof"` + OneofNested *Nested `protobuf:"bytes,3,opt,name=oneof_nested,json=oneofNested,proto3,oneof" json:"oneofNested"` } func (*Oneofs_OneofEnum) isOneofs_Union() {} diff --git a/reflect/protoreflect/type.go b/reflect/protoreflect/type.go index 60ff62b4c..79b969a7d 100644 --- a/reflect/protoreflect/type.go +++ b/reflect/protoreflect/type.go @@ -425,6 +425,10 @@ type OneofDescriptor interface { // Fields is a list of fields belonging to this oneof. Fields() FieldDescriptors + // JSONName reports the name used for JSON serialization. + // It is usually the camel-cased form of the oneof name. + JSONName() string + isOneofDescriptor } type isOneofDescriptor interface{ ProtoType(OneofDescriptor) } diff --git a/types/known/structpb/struct.pb.go b/types/known/structpb/struct.pb.go index d2bac8b88..38260b676 100644 --- a/types/known/structpb/struct.pb.go +++ b/types/known/structpb/struct.pb.go @@ -291,7 +291,7 @@ type Value struct { // *Value_BoolValue // *Value_StructValue // *Value_ListValue - Kind isValue_Kind `protobuf_oneof:"kind"` + Kind isValue_Kind `protobuf_oneof:"kind" json:"kind,omitempty"` } // NewValue constructs a Value from a general-purpose Go interface. @@ -526,32 +526,32 @@ type isValue_Kind interface { type Value_NullValue struct { // Represents a null value. - NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,proto3,enum=google.protobuf.NullValue,oneof"` + NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,proto3,enum=google.protobuf.NullValue,oneof" json:"nullValue"` } type Value_NumberValue struct { // Represents a double value. - NumberValue float64 `protobuf:"fixed64,2,opt,name=number_value,json=numberValue,proto3,oneof"` + NumberValue float64 `protobuf:"fixed64,2,opt,name=number_value,json=numberValue,proto3,oneof" json:"numberValue"` } type Value_StringValue struct { // Represents a string value. - StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,proto3,oneof"` + StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,proto3,oneof" json:"stringValue"` } type Value_BoolValue struct { // Represents a boolean value. - BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,proto3,oneof"` + BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,proto3,oneof" json:"boolValue"` } type Value_StructValue struct { // Represents a structured value. - StructValue *Struct `protobuf:"bytes,5,opt,name=struct_value,json=structValue,proto3,oneof"` + StructValue *Struct `protobuf:"bytes,5,opt,name=struct_value,json=structValue,proto3,oneof" json:"structValue"` } type Value_ListValue struct { // Represents a repeated `Value`. - ListValue *ListValue `protobuf:"bytes,6,opt,name=list_value,json=listValue,proto3,oneof"` + ListValue *ListValue `protobuf:"bytes,6,opt,name=list_value,json=listValue,proto3,oneof" json:"listValue"` } func (*Value_NullValue) isValue_Kind() {}