@@ -13,6 +13,7 @@ import (
13
13
)
14
14
15
15
var listSchema * spec.Schema
16
+ var listSchemaWithPlaceholder * spec.Schema
16
17
var searchResultSchema * spec.Schema
17
18
var verbose bool
18
19
@@ -41,6 +42,30 @@ func init() {
41
42
},
42
43
}
43
44
45
+ listSchemaWithPlaceholder = & spec.Schema {
46
+ Type : "object" ,
47
+ Properties : map [string ]* spec.Schema {
48
+ "data" : {
49
+ Items : & spec.Schema {
50
+ Ref : "#/components/schemas/charge" ,
51
+ },
52
+ },
53
+ "has_more" : {
54
+ Type : "boolean" ,
55
+ },
56
+ "object" : {
57
+ Enum : []interface {}{"list" },
58
+ },
59
+ "total_count" : {
60
+ Type : "integer" ,
61
+ },
62
+ "url" : {
63
+ Type : "string" ,
64
+ Pattern : "^/v1/charges/[^/]+/nested_list" ,
65
+ },
66
+ },
67
+ }
68
+
44
69
searchResultSchema = & spec.Schema {
45
70
Type : "object" ,
46
71
Properties : map [string ]* spec.Schema {
@@ -339,6 +364,40 @@ func TestGenerateResponseData(t *testing.T) {
339
364
data .(map [string ]interface {})["customer" ])
340
365
}
341
366
367
+ // injected ID in list url
368
+ {
369
+ generator := DataGenerator {
370
+ testSpec .Components .Schemas ,
371
+ & spec.Fixtures {
372
+ Resources : map [spec.ResourceID ]interface {}{
373
+ spec .ResourceID ("charge" ): map [string ]interface {}{"id" : "ch_123" },
374
+ spec .ResourceID ("with_charges_list" ): map [string ]interface {}{
375
+ "charges_list" : map [string ]interface {}{
376
+ "url" : "/v1/charges" ,
377
+ },
378
+ },
379
+ },
380
+ },
381
+ verbose ,
382
+ }
383
+ data , err := generator .Generate (& GenerateParams {
384
+ Schema : & spec.Schema {
385
+ Type : "object" ,
386
+ Properties : map [string ]* spec.Schema {
387
+ "charges_list" : listSchemaWithPlaceholder ,
388
+ },
389
+ XResourceID : "with_charges_list" ,
390
+ },
391
+ })
392
+ assert .Nil (t , err )
393
+ chargesList := data .(map [string ]interface {})["charges_list" ]
394
+ assert .Equal (t , "list" , chargesList .(map [string ]interface {})["object" ])
395
+ assert .Equal (t , "/v1/charges/id_123/nested_list" , chargesList .(map [string ]interface {})["url" ])
396
+ assert .Equal (t ,
397
+ testFixtures .Resources ["charge" ].(map [string ]interface {})["id" ],
398
+ chargesList .(map [string ]interface {})["data" ].([]interface {})[0 ].(map [string ]interface {})["id" ])
399
+ }
400
+
342
401
// injected secondary ID
343
402
{
344
403
generator := DataGenerator {testSpec .Components .Schemas , & spec.Fixtures {
0 commit comments