feat(proto): create custom option for attribute subtype

pull/2031/head
irenarindos 4 years ago committed by Johan Brandhorst-Satzkorn
parent 6a37bd9710
commit e76db2cd13

@ -42,6 +42,11 @@ func parsePBs() {
in.generatedStructure.name = string(desc.Name())
for i := 0; i < desc.Fields().Len(); i++ {
fd := desc.Fields().Get(i)
opts := fd.Options().(*descriptorpb.FieldOptions)
if subtype := proto.GetExtension(opts, protooptions.E_Subtype).(string); subtype != "" && subtype != "default" {
// Skip rendering any fields except the default subtype field.
continue
}
if strutil.StrListContains(in.fieldFilter, string(fd.Name())) {
continue
}
@ -55,7 +60,6 @@ func parsePBs() {
sliceText = "[]"
}
// Add generate option info
opts := fd.Options().(*descriptorpb.FieldOptions)
if proto.GetExtension(opts, protooptions.E_GenerateSdkOption).(bool) {
fi.GenerateSdkOption = true
}

@ -15,6 +15,11 @@ extend google.protobuf.FieldOptions {
// generate_sdk_option is a directive used when generating the SDK to
// indicate that an option should be created for the field
bool generate_sdk_option = 85412;
// subtype is used for oneOf attribute subtypes, to identify that we only need to parse attributes
// 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;
}
message MaskMapping {

@ -93,6 +93,14 @@ var file_controller_custom_options_v1_options_proto_extTypes = []protoimpl.Exten
Tag: "varint,85412,opt,name=generate_sdk_option",
Filename: "controller/custom_options/v1/options.proto",
},
{
ExtendedType: (*descriptorpb.FieldOptions)(nil),
ExtensionType: (*string)(nil),
Field: 85555,
Name: "controller.custom_options.v1.subtype",
Tag: "bytes,85555,opt,name=subtype",
Filename: "controller/custom_options/v1/options.proto",
},
}
// Extension fields to descriptorpb.FieldOptions.
@ -109,6 +117,12 @@ var (
//
// optional bool generate_sdk_option = 85412;
E_GenerateSdkOption = &file_controller_custom_options_v1_options_proto_extTypes[1]
// subtype is used for oneOf attribute subtypes, to identify that we only need to parse attributes
// 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
//
// optional string subtype = 85555;
E_Subtype = &file_controller_custom_options_v1_options_proto_extTypes[2]
)
var File_controller_custom_options_v1_options_proto protoreflect.FileDescriptor
@ -136,12 +150,16 @@ var file_controller_custom_options_v1_options_proto_rawDesc = []byte{
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, 0xa4, 0x9b, 0x05, 0x20, 0x01, 0x28, 0x08,
0x52, 0x11, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x53, 0x64, 0x6b, 0x4f, 0x70, 0x74,
0x69, 0x6f, 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,
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, 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 (
@ -164,11 +182,12 @@ var file_controller_custom_options_v1_options_proto_goTypes = []interface{}{
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
0, // 2: controller.custom_options.v1.mask_mapping:type_name -> controller.custom_options.v1.MaskMapping
3, // [3:3] is the sub-list for method output_type
3, // [3:3] is the sub-list for method input_type
2, // [2:3] is the sub-list for extension type_name
0, // [0:2] is the sub-list for extension extendee
1, // 2: controller.custom_options.v1.subtype:extendee -> google.protobuf.FieldOptions
0, // 3: controller.custom_options.v1.mask_mapping:type_name -> controller.custom_options.v1.MaskMapping
4, // [4:4] is the sub-list for method output_type
4, // [4:4] is the sub-list for method input_type
3, // [3:4] is the sub-list for extension type_name
0, // [0:3] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
@ -198,7 +217,7 @@ func file_controller_custom_options_v1_options_proto_init() {
RawDescriptor: file_controller_custom_options_v1_options_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 2,
NumExtensions: 3,
NumServices: 0,
},
GoTypes: file_controller_custom_options_v1_options_proto_goTypes,

Loading…
Cancel
Save