@@ -197,6 +197,80 @@ func TestMessageToQueryParameters(t *testing.T) {
197197 }
198198}
199199
200+ func TestMessageToQueryParametersWithJsonName (t * testing.T ) {
201+ type test struct {
202+ MsgDescs []* protodescriptor.DescriptorProto
203+ Message string
204+ Params []swaggerParameterObject
205+ }
206+
207+ tests := []test {
208+ {
209+ MsgDescs : []* protodescriptor.DescriptorProto {
210+ & protodescriptor.DescriptorProto {
211+ Name : proto .String ("ExampleMessage" ),
212+ Field : []* protodescriptor.FieldDescriptorProto {
213+ {
214+ Name : proto .String ("test_field_a" ),
215+ Type : protodescriptor .FieldDescriptorProto_TYPE_STRING .Enum (),
216+ Number : proto .Int32 (1 ),
217+ JsonName : proto .String ("testFieldA" ),
218+ },
219+ },
220+ },
221+ },
222+ Message : "ExampleMessage" ,
223+ Params : []swaggerParameterObject {
224+ swaggerParameterObject {
225+ Name : "testFieldA" ,
226+ In : "query" ,
227+ Required : false ,
228+ Type : "string" ,
229+ },
230+ },
231+ },
232+ }
233+
234+ for _ , test := range tests {
235+ reg := descriptor .NewRegistry ()
236+ reg .SetUseJSONNamesForFields (true )
237+ msgs := []* descriptor.Message {}
238+ for _ , msgdesc := range test .MsgDescs {
239+ msgs = append (msgs , & descriptor.Message {DescriptorProto : msgdesc })
240+ }
241+ file := descriptor.File {
242+ FileDescriptorProto : & protodescriptor.FileDescriptorProto {
243+ SourceCodeInfo : & protodescriptor.SourceCodeInfo {},
244+ Name : proto .String ("example.proto" ),
245+ Package : proto .String ("example" ),
246+ Dependency : []string {},
247+ MessageType : test .MsgDescs ,
248+ Service : []* protodescriptor.ServiceDescriptorProto {},
249+ },
250+ GoPkg : descriptor.GoPackage {
251+ Path : "example.com/path/to/example/example.pb" ,
252+ Name : "example_pb" ,
253+ },
254+ Messages : msgs ,
255+ }
256+ reg .Load (& plugin.CodeGeneratorRequest {
257+ ProtoFile : []* protodescriptor.FileDescriptorProto {file .FileDescriptorProto },
258+ })
259+
260+ message , err := reg .LookupMsg ("" , ".example." + test .Message )
261+ if err != nil {
262+ t .Fatalf ("failed to lookup message: %s" , err )
263+ }
264+ params , err := messageToQueryParameters (message , reg , []descriptor.Parameter {})
265+ if err != nil {
266+ t .Fatalf ("failed to convert message to query parameters: %s" , err )
267+ }
268+ if ! reflect .DeepEqual (params , test .Params ) {
269+ t .Errorf ("expected %v, got %v" , test .Params , params )
270+ }
271+ }
272+ }
273+
200274func TestApplyTemplateSimple (t * testing.T ) {
201275 msgdesc := & protodescriptor.DescriptorProto {
202276 Name : proto .String ("ExampleMessage" ),
0 commit comments