@@ -2,6 +2,7 @@ package docs
22
33import (
44 "bytes"
5+ "reflect"
56 "testing"
67)
78
@@ -229,3 +230,115 @@ func TestOAS_BuildStream(t *testing.T) {
229230 })
230231 }
231232}
233+
234+ func Test_makeParametersMap (t * testing.T ) {
235+ t .Parallel ()
236+
237+ type args struct {
238+ parameters Parameters
239+ }
240+
241+ tests := []struct {
242+ name string
243+ args args
244+ want []map [string ]interface {}
245+ }{
246+ {
247+ name : "success-minimal" ,
248+ args : args {
249+ parameters : Parameters {{
250+ Name : "id" ,
251+ In : "path" ,
252+ Description : "test" ,
253+ Required : true ,
254+ Schema : Schema {Name : "id" , Type : "integer" },
255+ }},
256+ },
257+ want : []map [string ]interface {}{{
258+ "name" : "id" ,
259+ "in" : "path" ,
260+ "description" : "test" ,
261+ "required" : true ,
262+ "schema" : map [string ]interface {}{"name" : "id" , "type" : "integer" },
263+ }},
264+ },
265+ {
266+ name : "success-full" ,
267+ args : args {
268+ parameters : Parameters {{
269+ Name : "id" ,
270+ In : "path" ,
271+ Description : "test" ,
272+ Required : true ,
273+ Schema : Schema {
274+ Name : "id" ,
275+ Type : "integer" ,
276+ Properties : SchemaProperties {{Name : "id" , Type : "integer" }},
277+ },
278+ }},
279+ },
280+ want : []map [string ]interface {}{{
281+ "name" : "id" ,
282+ "in" : "path" ,
283+ "description" : "test" ,
284+ "required" : true ,
285+ "schema" : map [string ]interface {}{
286+ "name" : "id" ,
287+ "type" : "integer" ,
288+ "properties" : map [string ]interface {}{
289+ "id" : map [string ]interface {}{"type" : "integer" },
290+ },
291+ },
292+ }},
293+ },
294+ {
295+ name : "success-ref" ,
296+ args : args {
297+ parameters : Parameters {{
298+ Name : "id" ,
299+ In : "path" ,
300+ Description : "test" ,
301+ Required : true ,
302+ Schema : Schema {Ref : "$some-ref" },
303+ }},
304+ },
305+ want : []map [string ]interface {}{{
306+ "name" : "id" ,
307+ "in" : "path" ,
308+ "description" : "test" ,
309+ "required" : true ,
310+ "schema" : map [string ]interface {}{"$ref" : "$some-ref" },
311+ }},
312+ },
313+ {
314+ name : "success-xml-entry" ,
315+ args : args {
316+ parameters : Parameters {{
317+ Name : "id" ,
318+ In : "path" ,
319+ Description : "test" ,
320+ Required : true ,
321+ Schema : Schema {Name : "id" , Type : "integer" , XML : XMLEntry {Name : "id" }},
322+ }},
323+ },
324+ want : []map [string ]interface {}{{
325+ "name" : "id" ,
326+ "in" : "path" ,
327+ "description" : "test" ,
328+ "required" : true ,
329+ "schema" : map [string ]interface {}{"name" : "id" , "type" : "integer" , "xml" : map [string ]interface {}{"name" : "id" }},
330+ }},
331+ },
332+ }
333+ for _ , tt := range tests {
334+ trn := tt
335+
336+ t .Run (trn .name , func (t * testing.T ) {
337+ t .Parallel ()
338+
339+ if got := makeParametersMap (trn .args .parameters ); ! reflect .DeepEqual (got , trn .want ) {
340+ t .Errorf ("makeParametersMap() = %+v, want %+v" , got , trn .want )
341+ }
342+ })
343+ }
344+ }
0 commit comments