@@ -486,6 +486,119 @@ func TestMessageToQueryParametersWithOmitEnumDefaultValue(t *testing.T) {
486
486
}
487
487
}
488
488
489
+ func TestMessageToQueryParametersWithRepeatedPathParamSeparator (t * testing.T ) {
490
+ type test struct {
491
+ MsgDescs []* descriptorpb.DescriptorProto
492
+ Message string
493
+ Params []openapiParameterObject
494
+ RepatedPathParam string
495
+ }
496
+
497
+ tests := []test {
498
+ {
499
+ MsgDescs : []* descriptorpb.DescriptorProto {
500
+ {
501
+ Name : proto .String ("ExampleMessage" ),
502
+ Field : []* descriptorpb.FieldDescriptorProto {
503
+ {
504
+ Name : proto .String ("c" ),
505
+ Type : descriptorpb .FieldDescriptorProto_TYPE_STRING .Enum (),
506
+ Label : descriptorpb .FieldDescriptorProto_LABEL_REPEATED .Enum (),
507
+ Number : proto .Int32 (3 ),
508
+ },
509
+ },
510
+ },
511
+ },
512
+ Message : "ExampleMessage" ,
513
+ Params : []openapiParameterObject {
514
+ {
515
+ Name : "c" ,
516
+ In : "query" ,
517
+ Required : false ,
518
+ Type : "array" ,
519
+ CollectionFormat : "ssv" ,
520
+ },
521
+ },
522
+ RepatedPathParam : "ssv" ,
523
+ },
524
+ {
525
+ MsgDescs : []* descriptorpb.DescriptorProto {
526
+ {
527
+ Name : proto .String ("ExampleMessage" ),
528
+ Field : []* descriptorpb.FieldDescriptorProto {
529
+ {
530
+ Name : proto .String ("c" ),
531
+ Type : descriptorpb .FieldDescriptorProto_TYPE_STRING .Enum (),
532
+ Label : descriptorpb .FieldDescriptorProto_LABEL_REPEATED .Enum (),
533
+ Number : proto .Int32 (3 ),
534
+ },
535
+ },
536
+ },
537
+ },
538
+ Message : "ExampleMessage" ,
539
+ Params : []openapiParameterObject {
540
+ {
541
+ Name : "c" ,
542
+ In : "query" ,
543
+ Required : false ,
544
+ Type : "array" ,
545
+ CollectionFormat : "pipes" ,
546
+ },
547
+ },
548
+ RepatedPathParam : "pipes" ,
549
+ },
550
+ }
551
+
552
+ for _ , test := range tests {
553
+ reg := descriptor .NewRegistry ()
554
+ reg .SetRepeatedPathParamSeparator (test .RepatedPathParam )
555
+ msgs := []* descriptor.Message {}
556
+ for _ , msgdesc := range test .MsgDescs {
557
+ msgs = append (msgs , & descriptor.Message {DescriptorProto : msgdesc })
558
+ }
559
+ file := descriptor.File {
560
+ FileDescriptorProto : & descriptorpb.FileDescriptorProto {
561
+ SourceCodeInfo : & descriptorpb.SourceCodeInfo {},
562
+ Name : proto .String ("example.proto" ),
563
+ Package : proto .String ("example" ),
564
+ Dependency : []string {},
565
+ MessageType : test .MsgDescs ,
566
+ Service : []* descriptorpb.ServiceDescriptorProto {},
567
+ Options : & descriptorpb.FileOptions {
568
+ GoPackage : proto .String ("github.com/grpc-ecosystem/grpc-gateway/runtime/internal/examplepb;example" ),
569
+ },
570
+ },
571
+ GoPkg : descriptor.GoPackage {
572
+ Path : "example.com/path/to/example/example.pb" ,
573
+ Name : "example_pb" ,
574
+ },
575
+ Messages : msgs ,
576
+ }
577
+ err := reg .Load (& pluginpb.CodeGeneratorRequest {
578
+ ProtoFile : []* descriptorpb.FileDescriptorProto {file .FileDescriptorProto },
579
+ })
580
+ if err != nil {
581
+ t .Fatalf ("failed to load code generator request: %v" , err )
582
+ }
583
+
584
+ message , err := reg .LookupMsg ("" , ".example." + test .Message )
585
+ if err != nil {
586
+ t .Fatalf ("failed to lookup message: %s" , err )
587
+ }
588
+ params , err := messageToQueryParameters (message , reg , []descriptor.Parameter {}, nil , "" )
589
+ if err != nil {
590
+ t .Fatalf ("failed to convert message to query parameters: %s" , err )
591
+ }
592
+ // avoid checking Items for array types
593
+ for i := range params {
594
+ params [i ].Items = nil
595
+ }
596
+ if ! reflect .DeepEqual (params , test .Params ) {
597
+ t .Errorf ("expected %v, got %v" , test .Params , params )
598
+ }
599
+ }
600
+ }
601
+
489
602
func TestMessageToQueryParameters (t * testing.T ) {
490
603
type test struct {
491
604
MsgDescs []* descriptorpb.DescriptorProto
0 commit comments