8
8
"sort"
9
9
"strings"
10
10
11
- "github.com/GoogleCloudPlatform/protoc-gen-bq-schema/v2 /protos"
11
+ "github.com/GoogleCloudPlatform/protoc-gen-bq-schema/v3 /protos"
12
12
"github.com/golang/glog"
13
13
"google.golang.org/protobuf/encoding/prototext"
14
14
"google.golang.org/protobuf/proto"
47
47
48
48
descriptor .FieldDescriptorProto_TYPE_STRING : "STRING" ,
49
49
descriptor .FieldDescriptorProto_TYPE_BYTES : "BYTES" ,
50
- descriptor .FieldDescriptorProto_TYPE_ENUM : "STRING " ,
50
+ descriptor .FieldDescriptorProto_TYPE_ENUM : "INTEGER " ,
51
51
52
52
descriptor .FieldDescriptorProto_TYPE_BOOL : "BOOLEAN" ,
53
53
@@ -401,6 +401,15 @@ func handleSingleMessageOpt(file *descriptor.FileDescriptorProto, requestParam s
401
401
})
402
402
}
403
403
404
+ // enumAsStringOpt handles --bq-schema_opt=enum-as-string in protoc params.
405
+ // providing that param tesll protoc-gen-bq-schema to treat enums as strings.
406
+ func enumAsStringOpt (requestParam string ) {
407
+ if ! strings .Contains (requestParam , "enum-as-string" ) {
408
+ return
409
+ }
410
+ typeFromFieldType [descriptor .FieldDescriptorProto_TYPE_ENUM ] = "STRING"
411
+ }
412
+
404
413
func Convert (req * plugin.CodeGeneratorRequest ) (* plugin.CodeGeneratorResponse , error ) {
405
414
generateTargets := make (map [string ]bool )
406
415
for _ , file := range req .GetFileToGenerate () {
@@ -412,6 +421,7 @@ func Convert(req *plugin.CodeGeneratorRequest) (*plugin.CodeGeneratorResponse, e
412
421
MinimumEdition : proto .Int32 (int32 (descriptor .Edition_EDITION_PROTO2 )),
413
422
MaximumEdition : proto .Int32 (int32 (descriptor .Edition_EDITION_MAX )),
414
423
}
424
+ enumAsStringOpt (req .GetParameter ())
415
425
for _ , file := range req .GetProtoFile () {
416
426
for msgIndex , msg := range file .GetMessageType () {
417
427
glog .V (1 ).Infof ("Loading a message type %s from package %s" , msg .GetName (), file .GetPackage ())
0 commit comments