From 8cbbfbe3a0caf7b689b681be920d866f52c8dd51 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Fri, 1 Apr 2022 08:36:09 -0400 Subject: [PATCH] feat(proto): Add new field option to indicate a in id for subtypes This allows for marking a field in a message as an id that can be used to determine the message's subtype. When creating some resources, an id from a related resource is used to indicate the resource's subtype, since the resource must have the same subtype as the related resource. --- .../custom_options/v1/options.proto | 4 ++ sdk/pbs/controller/protooptions/options.pb.go | 55 +++++++++++++------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/internal/proto/controller/custom_options/v1/options.proto b/internal/proto/controller/custom_options/v1/options.proto index 90d3fa0400..ca488ecc13 100644 --- a/internal/proto/controller/custom_options/v1/options.proto +++ b/internal/proto/controller/custom_options/v1/options.proto @@ -20,6 +20,10 @@ extend google.protobuf.FieldOptions { // of oneOf once and not for each option when generating the API // This will serve as a JSON key, used to transform that into the key the protobuf expects string subtype = 85555; + + // subtype_source_id is used to indicate that a field provided an id that can be used + // to determine the subtype of a message. + bool subtype_source_id = 85556; } extend google.protobuf.FileOptions { diff --git a/sdk/pbs/controller/protooptions/options.pb.go b/sdk/pbs/controller/protooptions/options.pb.go index f0e563f9d1..bbccf1840d 100644 --- a/sdk/pbs/controller/protooptions/options.pb.go +++ b/sdk/pbs/controller/protooptions/options.pb.go @@ -101,6 +101,14 @@ var file_controller_custom_options_v1_options_proto_extTypes = []protoimpl.Exten Tag: "bytes,85555,opt,name=subtype", Filename: "controller/custom_options/v1/options.proto", }, + { + ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtensionType: (*bool)(nil), + Field: 85556, + Name: "controller.custom_options.v1.subtype_source_id", + Tag: "varint,85556,opt,name=subtype_source_id", + Filename: "controller/custom_options/v1/options.proto", + }, { ExtendedType: (*descriptorpb.FileOptions)(nil), ExtensionType: (*string)(nil), @@ -131,6 +139,11 @@ var ( // // optional string subtype = 85555; E_Subtype = &file_controller_custom_options_v1_options_proto_extTypes[2] + // subtype_source_id is used to indicate that a field provided an id that can be used + // to determine the subtype of a message. + // + // optional bool subtype_source_id = 85556; + E_SubtypeSourceId = &file_controller_custom_options_v1_options_proto_extTypes[3] ) // Extension fields to descriptorpb.FileOptions. @@ -138,7 +151,7 @@ var ( // domain is used to associate the messages in a file with a domain package. // // optional string domain = 85556; - E_Domain = &file_controller_custom_options_v1_options_proto_extTypes[3] + E_Domain = &file_controller_custom_options_v1_options_proto_extTypes[4] ) var File_controller_custom_options_v1_options_proto protoreflect.FileDescriptor @@ -169,16 +182,21 @@ var file_controller_custom_options_v1_options_proto_rawDesc = []byte{ 0x69, 0x6f, 0x6e, 0x3a, 0x39, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb3, 0x9c, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x62, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x36, - 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4f, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb4, 0x9c, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x42, 0x4c, 0x5a, 0x4a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, - 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x73, 0x64, 0x6b, 0x2f, 0x70, 0x62, 0x73, 0x2f, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x6f, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x62, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x4b, + 0x0a, 0x11, 0x73, 0x75, 0x62, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x5f, 0x69, 0x64, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0xb4, 0x9c, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x73, 0x75, 0x62, 0x74, + 0x79, 0x70, 0x65, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x3a, 0x36, 0x0a, 0x06, 0x64, + 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0xb4, 0x9c, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, + 0x61, 0x69, 0x6e, 0x42, 0x4c, 0x5a, 0x4a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, + 0x64, 0x61, 0x72, 0x79, 0x2f, 0x73, 0x64, 0x6b, 0x2f, 0x70, 0x62, 0x73, 0x2f, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x6f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -203,12 +221,13 @@ var file_controller_custom_options_v1_options_proto_depIdxs = []int32{ 1, // 0: controller.custom_options.v1.mask_mapping:extendee -> google.protobuf.FieldOptions 1, // 1: controller.custom_options.v1.generate_sdk_option:extendee -> google.protobuf.FieldOptions 1, // 2: controller.custom_options.v1.subtype:extendee -> google.protobuf.FieldOptions - 2, // 3: controller.custom_options.v1.domain:extendee -> google.protobuf.FileOptions - 0, // 4: controller.custom_options.v1.mask_mapping:type_name -> controller.custom_options.v1.MaskMapping - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 4, // [4:5] is the sub-list for extension type_name - 0, // [0:4] is the sub-list for extension extendee + 1, // 3: controller.custom_options.v1.subtype_source_id:extendee -> google.protobuf.FieldOptions + 2, // 4: controller.custom_options.v1.domain:extendee -> google.protobuf.FileOptions + 0, // 5: controller.custom_options.v1.mask_mapping:type_name -> controller.custom_options.v1.MaskMapping + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 5, // [5:6] is the sub-list for extension type_name + 0, // [0:5] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } @@ -238,7 +257,7 @@ func file_controller_custom_options_v1_options_proto_init() { RawDescriptor: file_controller_custom_options_v1_options_proto_rawDesc, NumEnums: 0, NumMessages: 1, - NumExtensions: 4, + NumExtensions: 5, NumServices: 0, }, GoTypes: file_controller_custom_options_v1_options_proto_goTypes,