diff --git a/cmd/protoc-gen-alias/Makefile b/cmd/protoc-gen-alias/Makefile new file mode 100644 index 0000000000..153705fb14 --- /dev/null +++ b/cmd/protoc-gen-alias/Makefile @@ -0,0 +1,5 @@ +test: build + cd test && make clean test + +build: + go install . \ No newline at end of file diff --git a/cmd/protoc-gen-alias/README.md b/cmd/protoc-gen-alias/README.md new file mode 100644 index 0000000000..a8cd269483 --- /dev/null +++ b/cmd/protoc-gen-alias/README.md @@ -0,0 +1,27 @@ +# protoc-gen-alias + +`protoc-gen-alias` is a plugin for protoc which type alias for all messages, such that one protobuf definition can +be consumed from many Go packages + +## Usage + +Usage is typically through `buf`, but you can use directly. +See `test/Makefile` for example usage. + +## Configuration + +The plugin looks for a comment like `+cue-gen:Simple:versions:v1,v1alpha` on the package. +This will generate aliases to the current version, for all versions listed (the current version is ignored). + +## Examples Of Generated Code + +```go +// Code generated by protoc-gen-jsonshim. DO NOT EDIT. +type Simple = v1.Simple +type Simple_Name = v1.Simple_Name +type Simple_Number = v1.Simple_Number +type SimpleWithMap = v1.SimpleWithMap +type SimpleWithMap_Nested = v1.SimpleWithMap_Nested +type ReferencedMap = v1.ReferencedMap +type ImportedReference = v1.ImportedReference +``` diff --git a/cmd/protoc-gen-alias/main.go b/cmd/protoc-gen-alias/main.go new file mode 100644 index 0000000000..be8bd0ff02 --- /dev/null +++ b/cmd/protoc-gen-alias/main.go @@ -0,0 +1,107 @@ +// Copyright 2019 Istio Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "path/filepath" + "strings" + + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/types/descriptorpb" +) + +func main() { + protogen.Options{}.Run(func(gen *protogen.Plugin) error { + for _, f := range gen.Files { + if !f.Generate { + continue + } + generateFile(gen, f) + } + return nil + }) +} + +func generateFile(gen *protogen.Plugin, file *protogen.File) { + ourVersion := filepath.Base(filepath.Dir(file.Desc.Path())) + var versions []string + for _, msg := range file.Messages { + for _, line := range strings.Split(msg.Comments.Leading.String(), "\n") { + // Looking for something like '// +cue-gen:Simple:versions:v1,v1alpha' + if strings.HasPrefix(line, "// +cue-gen:") { + items := strings.Split(line, ":") + if len(items) != 4 { + continue + } + if items[2] == "versions" { + for _, v := range strings.Split(items[3], ",") { + if v != ourVersion { + versions = append(versions, v) + } + } + } + } + } + } + if len(versions) == 0 { + return + } + base := filepath.Dir(filepath.Dir(file.Desc.Path())) + fnamePrefix := filepath.Base(file.GeneratedFilenamePrefix) + for _, aliasVersion := range versions { + filename := filepath.Join(base, aliasVersion, fnamePrefix+"_alias.gen.go") + p := gen.NewGeneratedFile(filename, file.GoImportPath) + + p.P("// Code generated by protoc-gen-alias. DO NOT EDIT.") + p.P("package ", aliasVersion) + p.P(`import `, file.GoImportPath) + var processMessages func([]*protogen.Message) + var processEnums func([]*protogen.Enum) + var processOneofs func([]*protogen.Oneof) + + processEnums = func(enums []*protogen.Enum) { + for _, e := range enums { + typeName := e.GoIdent.GoName + p.P(`type `, typeName, `= `, file.GoPackageName, ".", e.GoIdent) + for _, v := range e.Values { + p.P(`const `, v.GoIdent, " ", typeName, `= `, file.GoPackageName, ".", v.GoIdent) + } + } + } + processOneofs = func(oneofs []*protogen.Oneof) { + for _, e := range oneofs { + for _, f := range e.Fields { + p.P(`type `, f.GoIdent, `= `, file.GoPackageName, ".", f.GoIdent) + } + } + } + processMessages = func(messages []*protogen.Message) { + for _, message := range messages { + // skip maps in protos. + if message.Desc.Options().(*descriptorpb.MessageOptions).GetMapEntry() { + continue + } + typeName := message.GoIdent.GoName + p.P(`type `, typeName, "= ", file.GoPackageName, ".", message.GoIdent) + processMessages(message.Messages) + processEnums(message.Enums) + processOneofs(message.Oneofs) + } + } + processMessages(file.Messages) + processEnums(file.Enums) + + } +} diff --git a/cmd/protoc-gen-alias/test/Makefile b/cmd/protoc-gen-alias/test/Makefile new file mode 100644 index 0000000000..0147838228 --- /dev/null +++ b/cmd/protoc-gen-alias/test/Makefile @@ -0,0 +1,21 @@ + +go_package = istio.io/tools/cmd/protoc-gen-golang-jsonshim/test/generated + +all: clean test + +clean: + if [ -d "generated" ]; then rm -rf generated; fi + +test: generate gobuild gotest + +generate: + if [ ! -d "generated" ]; then mkdir generated; fi + protoc --go_out=. --go_opt=paths=source_relative \ + --alias_out=. --alias_opt=paths=source_relative \ + v1/*.proto + +gobuild: + go build ./... + +gotest: + go test . diff --git a/cmd/protoc-gen-alias/test/alias_test.go b/cmd/protoc-gen-alias/test/alias_test.go new file mode 100644 index 0000000000..2c028ec5a4 --- /dev/null +++ b/cmd/protoc-gen-alias/test/alias_test.go @@ -0,0 +1,65 @@ +// Copyright 2019 Istio Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package test + +import ( + "testing" + + "google.golang.org/protobuf/proto" + + v1 "istio.io/tools/cmd/protoc-gen-alias/test/v1" + "istio.io/tools/cmd/protoc-gen-alias/test/v1alpha" +) + +func TestSimpleCase(t *testing.T) { + concrete := &v1.Simple{ + FieldA: 1, + FieldB: "test", + FieldC: &v1.Simple_Name{ + Name: "test", + }, + } + alias := &v1alpha.Simple{ + FieldA: 1, + FieldB: "test", + FieldC: &v1alpha.Simple_Name{ + Name: "test", + }, + } + mixedAliasFirst := &v1alpha.Simple{ + FieldA: 1, + FieldB: "test", + FieldC: &v1.Simple_Name{ + Name: "test", + }, + } + mixedConcreteFirst := &v1.Simple{ + FieldA: 1, + FieldB: "test", + FieldC: &v1alpha.Simple_Name{ + Name: "test", + }, + } + // Test we can do proto operations + proto.Equal(concrete, alias) + proto.Equal(concrete, mixedConcreteFirst) + proto.Equal(concrete, mixedAliasFirst) + if proto.MessageName(mixedConcreteFirst).Name() != "Simple" { + t.Errorf("proto name should be Simple") + } + if proto.MessageName(mixedAliasFirst).Name() != "Simple" { + t.Errorf("proto name should be Simple") + } +} diff --git a/cmd/protoc-gen-alias/test/v1/external.pb.go b/cmd/protoc-gen-alias/test/v1/external.pb.go new file mode 100644 index 0000000000..332b9101ad --- /dev/null +++ b/cmd/protoc-gen-alias/test/v1/external.pb.go @@ -0,0 +1,245 @@ +// Copyright 2018 Istio Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v4.25.3 +// source: v1/external.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ExternalSimple struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FieldC uint32 `protobuf:"varint,1,opt,name=fieldC,proto3" json:"fieldC,omitempty"` + FieldD *ExternalSimple_ExternalNested `protobuf:"bytes,2,opt,name=fieldD,proto3" json:"fieldD,omitempty"` +} + +func (x *ExternalSimple) Reset() { + *x = ExternalSimple{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_external_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ExternalSimple) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ExternalSimple) ProtoMessage() {} + +func (x *ExternalSimple) ProtoReflect() protoreflect.Message { + mi := &file_v1_external_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ExternalSimple.ProtoReflect.Descriptor instead. +func (*ExternalSimple) Descriptor() ([]byte, []int) { + return file_v1_external_proto_rawDescGZIP(), []int{0} +} + +func (x *ExternalSimple) GetFieldC() uint32 { + if x != nil { + return x.FieldC + } + return 0 +} + +func (x *ExternalSimple) GetFieldD() *ExternalSimple_ExternalNested { + if x != nil { + return x.FieldD + } + return nil +} + +type ExternalSimple_ExternalNested struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FieldA map[string]string `protobuf:"bytes,1,rep,name=fieldA,proto3" json:"fieldA,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *ExternalSimple_ExternalNested) Reset() { + *x = ExternalSimple_ExternalNested{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_external_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ExternalSimple_ExternalNested) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ExternalSimple_ExternalNested) ProtoMessage() {} + +func (x *ExternalSimple_ExternalNested) ProtoReflect() protoreflect.Message { + mi := &file_v1_external_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ExternalSimple_ExternalNested.ProtoReflect.Descriptor instead. +func (*ExternalSimple_ExternalNested) Descriptor() ([]byte, []int) { + return file_v1_external_proto_rawDescGZIP(), []int{0, 0} +} + +func (x *ExternalSimple_ExternalNested) GetFieldA() map[string]string { + if x != nil { + return x.FieldA + } + return nil +} + +var File_v1_external_proto protoreflect.FileDescriptor + +var file_v1_external_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x76, 0x31, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x22, 0x94, 0x02, 0x0a, 0x0e, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, + 0x64, 0x43, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x43, + 0x12, 0x47, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x2f, 0x2e, 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x69, 0x6d, 0x70, + 0x6c, 0x65, 0x2e, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x4e, 0x65, 0x73, 0x74, 0x65, + 0x64, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x44, 0x1a, 0xa0, 0x01, 0x0a, 0x0e, 0x45, 0x78, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x12, 0x53, 0x0a, 0x06, + 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3b, 0x2e, 0x69, + 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, + 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x45, + 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2e, 0x46, 0x69, + 0x65, 0x6c, 0x64, 0x41, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, + 0x41, 0x1a, 0x39, 0x0a, 0x0b, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x2d, 0x5a, 0x2b, + 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x69, 0x6f, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x63, + 0x6d, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x61, 0x6c, + 0x69, 0x61, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_v1_external_proto_rawDescOnce sync.Once + file_v1_external_proto_rawDescData = file_v1_external_proto_rawDesc +) + +func file_v1_external_proto_rawDescGZIP() []byte { + file_v1_external_proto_rawDescOnce.Do(func() { + file_v1_external_proto_rawDescData = protoimpl.X.CompressGZIP(file_v1_external_proto_rawDescData) + }) + return file_v1_external_proto_rawDescData +} + +var file_v1_external_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_v1_external_proto_goTypes = []interface{}{ + (*ExternalSimple)(nil), // 0: istio.tools.test.ExternalSimple + (*ExternalSimple_ExternalNested)(nil), // 1: istio.tools.test.ExternalSimple.ExternalNested + nil, // 2: istio.tools.test.ExternalSimple.ExternalNested.FieldAEntry +} +var file_v1_external_proto_depIdxs = []int32{ + 1, // 0: istio.tools.test.ExternalSimple.fieldD:type_name -> istio.tools.test.ExternalSimple.ExternalNested + 2, // 1: istio.tools.test.ExternalSimple.ExternalNested.fieldA:type_name -> istio.tools.test.ExternalSimple.ExternalNested.FieldAEntry + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_v1_external_proto_init() } +func file_v1_external_proto_init() { + if File_v1_external_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_v1_external_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ExternalSimple); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_external_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ExternalSimple_ExternalNested); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_v1_external_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_v1_external_proto_goTypes, + DependencyIndexes: file_v1_external_proto_depIdxs, + MessageInfos: file_v1_external_proto_msgTypes, + }.Build() + File_v1_external_proto = out.File + file_v1_external_proto_rawDesc = nil + file_v1_external_proto_goTypes = nil + file_v1_external_proto_depIdxs = nil +} diff --git a/cmd/protoc-gen-alias/test/v1/external.proto b/cmd/protoc-gen-alias/test/v1/external.proto new file mode 100644 index 0000000000..52f5017446 --- /dev/null +++ b/cmd/protoc-gen-alias/test/v1/external.proto @@ -0,0 +1,27 @@ +// Copyright 2018 Istio Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package istio.tools.test; + +option go_package = "istio.io/tools/cmd/protoc-gen-alias/test/v1"; + +message ExternalSimple { + uint32 fieldC = 1; + message ExternalNested { + map fieldA = 1; + } + ExternalNested fieldD = 2; +} diff --git a/cmd/protoc-gen-alias/test/v1/types.pb.go b/cmd/protoc-gen-alias/test/v1/types.pb.go new file mode 100644 index 0000000000..4d10ff0ced --- /dev/null +++ b/cmd/protoc-gen-alias/test/v1/types.pb.go @@ -0,0 +1,552 @@ +// Copyright 2018 Istio Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v4.25.3 +// source: v1/types.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Simple case +// +cue-gen:Simple:versions:v1,v1alpha +type Simple struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FieldA uint32 `protobuf:"varint,1,opt,name=fieldA,proto3" json:"fieldA,omitempty"` + FieldB string `protobuf:"bytes,2,opt,name=fieldB,proto3" json:"fieldB,omitempty"` + // Types that are assignable to FieldC: + // + // *Simple_Name + // *Simple_Number + FieldC isSimple_FieldC `protobuf_oneof:"fieldC"` +} + +func (x *Simple) Reset() { + *x = Simple{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Simple) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Simple) ProtoMessage() {} + +func (x *Simple) ProtoReflect() protoreflect.Message { + mi := &file_v1_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Simple.ProtoReflect.Descriptor instead. +func (*Simple) Descriptor() ([]byte, []int) { + return file_v1_types_proto_rawDescGZIP(), []int{0} +} + +func (x *Simple) GetFieldA() uint32 { + if x != nil { + return x.FieldA + } + return 0 +} + +func (x *Simple) GetFieldB() string { + if x != nil { + return x.FieldB + } + return "" +} + +func (m *Simple) GetFieldC() isSimple_FieldC { + if m != nil { + return m.FieldC + } + return nil +} + +func (x *Simple) GetName() string { + if x, ok := x.GetFieldC().(*Simple_Name); ok { + return x.Name + } + return "" +} + +func (x *Simple) GetNumber() uint32 { + if x, ok := x.GetFieldC().(*Simple_Number); ok { + return x.Number + } + return 0 +} + +type isSimple_FieldC interface { + isSimple_FieldC() +} + +type Simple_Name struct { + Name string `protobuf:"bytes,3,opt,name=name,proto3,oneof"` +} + +type Simple_Number struct { + Number uint32 `protobuf:"varint,4,opt,name=number,proto3,oneof"` +} + +func (*Simple_Name) isSimple_FieldC() {} + +func (*Simple_Number) isSimple_FieldC() {} + +// Simple case with map and map field should not have MarshalJSON/UnmarshalJSON +type SimpleWithMap struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FieldA uint32 `protobuf:"varint,1,opt,name=fieldA,proto3" json:"fieldA,omitempty"` + FieldB string `protobuf:"bytes,2,opt,name=fieldB,proto3" json:"fieldB,omitempty"` + FieldC map[string]string `protobuf:"bytes,3,rep,name=fieldC,proto3" json:"fieldC,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + FieldD *SimpleWithMap_Nested `protobuf:"bytes,4,opt,name=fieldD,proto3" json:"fieldD,omitempty"` +} + +func (x *SimpleWithMap) Reset() { + *x = SimpleWithMap{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_types_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SimpleWithMap) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SimpleWithMap) ProtoMessage() {} + +func (x *SimpleWithMap) ProtoReflect() protoreflect.Message { + mi := &file_v1_types_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SimpleWithMap.ProtoReflect.Descriptor instead. +func (*SimpleWithMap) Descriptor() ([]byte, []int) { + return file_v1_types_proto_rawDescGZIP(), []int{1} +} + +func (x *SimpleWithMap) GetFieldA() uint32 { + if x != nil { + return x.FieldA + } + return 0 +} + +func (x *SimpleWithMap) GetFieldB() string { + if x != nil { + return x.FieldB + } + return "" +} + +func (x *SimpleWithMap) GetFieldC() map[string]string { + if x != nil { + return x.FieldC + } + return nil +} + +func (x *SimpleWithMap) GetFieldD() *SimpleWithMap_Nested { + if x != nil { + return x.FieldD + } + return nil +} + +// verify no MarshalJSON/UnmarshalJSON functions are created for referenced map +type ReferencedMap struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FieldA string `protobuf:"bytes,1,opt,name=fieldA,proto3" json:"fieldA,omitempty"` + FieldB *SimpleWithMap_Nested `protobuf:"bytes,2,opt,name=fieldB,proto3" json:"fieldB,omitempty"` +} + +func (x *ReferencedMap) Reset() { + *x = ReferencedMap{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_types_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReferencedMap) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReferencedMap) ProtoMessage() {} + +func (x *ReferencedMap) ProtoReflect() protoreflect.Message { + mi := &file_v1_types_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReferencedMap.ProtoReflect.Descriptor instead. +func (*ReferencedMap) Descriptor() ([]byte, []int) { + return file_v1_types_proto_rawDescGZIP(), []int{2} +} + +func (x *ReferencedMap) GetFieldA() string { + if x != nil { + return x.FieldA + } + return "" +} + +func (x *ReferencedMap) GetFieldB() *SimpleWithMap_Nested { + if x != nil { + return x.FieldB + } + return nil +} + +// verify no MarshalJSON/UnmarshalJSON functions are created for imported map +type ImportedReference struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FieldA uint32 `protobuf:"varint,1,opt,name=fieldA,proto3" json:"fieldA,omitempty"` + FieldB *ExternalSimple `protobuf:"bytes,2,opt,name=fieldB,proto3" json:"fieldB,omitempty"` +} + +func (x *ImportedReference) Reset() { + *x = ImportedReference{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_types_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ImportedReference) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ImportedReference) ProtoMessage() {} + +func (x *ImportedReference) ProtoReflect() protoreflect.Message { + mi := &file_v1_types_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ImportedReference.ProtoReflect.Descriptor instead. +func (*ImportedReference) Descriptor() ([]byte, []int) { + return file_v1_types_proto_rawDescGZIP(), []int{3} +} + +func (x *ImportedReference) GetFieldA() uint32 { + if x != nil { + return x.FieldA + } + return 0 +} + +func (x *ImportedReference) GetFieldB() *ExternalSimple { + if x != nil { + return x.FieldB + } + return nil +} + +type SimpleWithMap_Nested struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + NestedFieldD map[string]string `protobuf:"bytes,1,rep,name=nestedFieldD,proto3" json:"nestedFieldD,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *SimpleWithMap_Nested) Reset() { + *x = SimpleWithMap_Nested{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_types_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SimpleWithMap_Nested) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SimpleWithMap_Nested) ProtoMessage() {} + +func (x *SimpleWithMap_Nested) ProtoReflect() protoreflect.Message { + mi := &file_v1_types_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SimpleWithMap_Nested.ProtoReflect.Descriptor instead. +func (*SimpleWithMap_Nested) Descriptor() ([]byte, []int) { + return file_v1_types_proto_rawDescGZIP(), []int{1, 1} +} + +func (x *SimpleWithMap_Nested) GetNestedFieldD() map[string]string { + if x != nil { + return x.NestedFieldD + } + return nil +} + +var File_v1_types_proto protoreflect.FileDescriptor + +var file_v1_types_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x10, 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, 0x65, + 0x73, 0x74, 0x1a, 0x11, 0x76, 0x31, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x72, 0x0a, 0x06, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, + 0x42, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x12, + 0x14, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x42, + 0x08, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x43, 0x22, 0xa9, 0x03, 0x0a, 0x0d, 0x53, 0x69, + 0x6d, 0x70, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x4d, 0x61, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x66, + 0x69, 0x65, 0x6c, 0x64, 0x41, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x66, 0x69, 0x65, + 0x6c, 0x64, 0x41, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x12, 0x43, 0x0a, 0x06, 0x66, + 0x69, 0x65, 0x6c, 0x64, 0x43, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x69, 0x73, + 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x53, + 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x4d, 0x61, 0x70, 0x2e, 0x46, 0x69, 0x65, + 0x6c, 0x64, 0x43, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x43, + 0x12, 0x3e, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x26, 0x2e, 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x2e, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x4d, 0x61, + 0x70, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x44, + 0x1a, 0x39, 0x0a, 0x0b, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x43, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0xa7, 0x01, 0x0a, 0x06, + 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x12, 0x5c, 0x0a, 0x0c, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, + 0x46, 0x69, 0x65, 0x6c, 0x64, 0x44, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x38, 0x2e, 0x69, + 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, + 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x4d, 0x61, 0x70, 0x2e, 0x4e, 0x65, + 0x73, 0x74, 0x65, 0x64, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, + 0x44, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0c, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x46, 0x69, + 0x65, 0x6c, 0x64, 0x44, 0x1a, 0x3f, 0x0a, 0x11, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x46, 0x69, + 0x65, 0x6c, 0x64, 0x44, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x67, 0x0a, 0x0d, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, + 0x63, 0x65, 0x64, 0x4d, 0x61, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x12, 0x3e, + 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, + 0x2e, 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x2e, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x4d, 0x61, 0x70, 0x2e, + 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x22, 0x65, + 0x0a, 0x11, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, + 0x6e, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x41, 0x12, 0x38, 0x0a, 0x06, 0x66, + 0x69, 0x65, 0x6c, 0x64, 0x42, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x69, 0x73, + 0x74, 0x69, 0x6f, 0x2e, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, + 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x52, 0x06, 0x66, + 0x69, 0x65, 0x6c, 0x64, 0x42, 0x42, 0x2d, 0x5a, 0x2b, 0x69, 0x73, 0x74, 0x69, 0x6f, 0x2e, 0x69, + 0x6f, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x2f, 0x74, 0x65, 0x73, + 0x74, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_v1_types_proto_rawDescOnce sync.Once + file_v1_types_proto_rawDescData = file_v1_types_proto_rawDesc +) + +func file_v1_types_proto_rawDescGZIP() []byte { + file_v1_types_proto_rawDescOnce.Do(func() { + file_v1_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_v1_types_proto_rawDescData) + }) + return file_v1_types_proto_rawDescData +} + +var file_v1_types_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_v1_types_proto_goTypes = []interface{}{ + (*Simple)(nil), // 0: istio.tools.test.Simple + (*SimpleWithMap)(nil), // 1: istio.tools.test.SimpleWithMap + (*ReferencedMap)(nil), // 2: istio.tools.test.ReferencedMap + (*ImportedReference)(nil), // 3: istio.tools.test.ImportedReference + nil, // 4: istio.tools.test.SimpleWithMap.FieldCEntry + (*SimpleWithMap_Nested)(nil), // 5: istio.tools.test.SimpleWithMap.Nested + nil, // 6: istio.tools.test.SimpleWithMap.Nested.NestedFieldDEntry + (*ExternalSimple)(nil), // 7: istio.tools.test.ExternalSimple +} +var file_v1_types_proto_depIdxs = []int32{ + 4, // 0: istio.tools.test.SimpleWithMap.fieldC:type_name -> istio.tools.test.SimpleWithMap.FieldCEntry + 5, // 1: istio.tools.test.SimpleWithMap.fieldD:type_name -> istio.tools.test.SimpleWithMap.Nested + 5, // 2: istio.tools.test.ReferencedMap.fieldB:type_name -> istio.tools.test.SimpleWithMap.Nested + 7, // 3: istio.tools.test.ImportedReference.fieldB:type_name -> istio.tools.test.ExternalSimple + 6, // 4: istio.tools.test.SimpleWithMap.Nested.nestedFieldD:type_name -> istio.tools.test.SimpleWithMap.Nested.NestedFieldDEntry + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_v1_types_proto_init() } +func file_v1_types_proto_init() { + if File_v1_types_proto != nil { + return + } + file_v1_external_proto_init() + if !protoimpl.UnsafeEnabled { + file_v1_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Simple); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SimpleWithMap); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_types_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReferencedMap); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_types_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ImportedReference); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_types_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SimpleWithMap_Nested); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_v1_types_proto_msgTypes[0].OneofWrappers = []interface{}{ + (*Simple_Name)(nil), + (*Simple_Number)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_v1_types_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_v1_types_proto_goTypes, + DependencyIndexes: file_v1_types_proto_depIdxs, + MessageInfos: file_v1_types_proto_msgTypes, + }.Build() + File_v1_types_proto = out.File + file_v1_types_proto_rawDesc = nil + file_v1_types_proto_goTypes = nil + file_v1_types_proto_depIdxs = nil +} diff --git a/cmd/protoc-gen-alias/test/v1/types.proto b/cmd/protoc-gen-alias/test/v1/types.proto new file mode 100644 index 0000000000..e20af3a359 --- /dev/null +++ b/cmd/protoc-gen-alias/test/v1/types.proto @@ -0,0 +1,55 @@ +// Copyright 2018 Istio Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package istio.tools.test; + +option go_package = "istio.io/tools/cmd/protoc-gen-alias/test/v1"; + +import "v1/external.proto"; + +// Simple case +// +cue-gen:Simple:versions:v1,v1alpha +message Simple { + uint32 fieldA = 1; + string fieldB = 2; + oneof fieldC { + string name = 3; + uint32 number = 4; + } +} + +// Simple case with map and map field should not have MarshalJSON/UnmarshalJSON +message SimpleWithMap { + uint32 fieldA = 1; + string fieldB = 2; + map fieldC = 3; + message Nested { + map nestedFieldD = 1; + } + Nested fieldD = 4; +} + +// verify no MarshalJSON/UnmarshalJSON functions are created for referenced map +message ReferencedMap { + string fieldA = 1; + SimpleWithMap.Nested fieldB = 2; +} + +// verify no MarshalJSON/UnmarshalJSON functions are created for imported map +message ImportedReference { + uint32 fieldA = 1; + ExternalSimple fieldB = 2; +} \ No newline at end of file diff --git a/cmd/protoc-gen-alias/test/v1alpha/types_alias.gen.go b/cmd/protoc-gen-alias/test/v1alpha/types_alias.gen.go new file mode 100644 index 0000000000..a0ba6098e8 --- /dev/null +++ b/cmd/protoc-gen-alias/test/v1alpha/types_alias.gen.go @@ -0,0 +1,12 @@ +// Code generated by protoc-gen-alias. DO NOT EDIT. +package v1alpha + +import "istio.io/tools/cmd/protoc-gen-alias/test/v1" + +type Simple = v1.Simple +type Simple_Name = v1.Simple_Name +type Simple_Number = v1.Simple_Number +type SimpleWithMap = v1.SimpleWithMap +type SimpleWithMap_Nested = v1.SimpleWithMap_Nested +type ReferencedMap = v1.ReferencedMap +type ImportedReference = v1.ImportedReference