@@ -51,7 +51,7 @@ type pactFileV2 struct {
51
51
// Raw incoming interactions from the consumer test
52
52
interactions []* InteractionV2
53
53
54
- // Interactions are the annotated set the request/response expectations, with matching rules and generators
54
+ // Interactions are the annotated set the request/response expectations, with matching rules
55
55
Interactions []pactInteractionV2 `json:"interactions"`
56
56
57
57
Metadata map [string ]interface {} `json:"metadata"`
@@ -92,16 +92,16 @@ func (p *pactFileV2) generateV2PactFile() *pactFileV2 {
92
92
var requestBodyMatchingRules , requestHeaderMatchingRules , requestQueryMatchingRules , responseBodyMatchingRules , responseHeaderMatchingRules rule
93
93
var requestQuery map [string ]interface {}
94
94
95
- _ , requestQuery , requestQueryMatchingRules , _ = buildPactPart ( "" , interaction .Request .Query , make ( map [ string ] interface {}), "$.query" , make ( rule ), make ( rule ) )
96
- _ , serialisedInteraction .Request .Headers , requestHeaderMatchingRules , _ = buildPactPart ( "" , interaction .Request .Headers , make ( map [ string ] interface {}), "$.headers" , make ( rule ), make ( rule ) )
97
- _ , serialisedInteraction .Request .Body , requestBodyMatchingRules , _ = buildPactPart ( "" , interaction .Request .Body , make ( map [ string ] interface {}), "$.body" , make ( rule ), make ( rule ) )
98
- _ , serialisedInteraction .Response .Body , responseBodyMatchingRules , _ = buildPactPart ( "" , interaction .Response .Body , make ( map [ string ] interface {}), "$.body" , make ( rule ), make ( rule ) )
99
- _ , serialisedInteraction .Response .Headers , responseHeaderMatchingRules , _ = buildPactPart ( "" , interaction .Response .Headers , make ( map [ string ] interface {}), "$.headers" , make ( rule ), make ( rule ) )
95
+ requestQuery , requestQueryMatchingRules = buildPartV2 ( interaction .Request .Query , "$.query" )
96
+ serialisedInteraction .Request .Headers , requestHeaderMatchingRules = buildPartV2 ( interaction .Request .Headers , "$.headers" )
97
+ serialisedInteraction .Request .Body , requestBodyMatchingRules = buildPartV2 ( interaction .Request .Body , "$.body" )
98
+ serialisedInteraction .Response .Body , responseBodyMatchingRules = buildPartV2 ( interaction .Response .Body , "$.body" )
99
+ serialisedInteraction .Response .Headers , responseHeaderMatchingRules = buildPartV2 ( interaction .Response .Headers , "$.headers" )
100
100
101
101
buildPactRequestQueryV2 (requestQuery , interaction , & serialisedInteraction , p .Options )
102
102
buildPactRequestPathV2 (interaction , & serialisedInteraction )
103
- mergeRules (serialisedInteraction .Request .MatchingRules , requestHeaderMatchingRules )
104
103
mergeRules (serialisedInteraction .Request .MatchingRules , requestQueryMatchingRules )
104
+ mergeRules (serialisedInteraction .Request .MatchingRules , requestHeaderMatchingRules )
105
105
mergeRules (serialisedInteraction .Request .MatchingRules , requestBodyMatchingRules )
106
106
mergeRules (serialisedInteraction .Response .MatchingRules , responseBodyMatchingRules )
107
107
mergeRules (serialisedInteraction .Response .MatchingRules , responseHeaderMatchingRules )
@@ -119,7 +119,7 @@ const startList = "["
119
119
const endList = "]"
120
120
121
121
func recurseMapType (key string , value interface {}, body map [string ]interface {}, path string ,
122
- matchingRules rule , generators rule ) (string , map [string ]interface {}, rule , rule ) {
122
+ matchingRules rule ) (string , map [string ]interface {}, rule ) {
123
123
mapped := reflect .ValueOf (value )
124
124
entry := make (map [string ]interface {})
125
125
path = path + buildPath (key , "" )
@@ -132,16 +132,22 @@ func recurseMapType(key string, value interface{}, body map[string]interface{},
132
132
133
133
// Starting position
134
134
if key == "" {
135
- _ , body , matchingRules , generators = buildPactPart (k .String (), v .Interface (), copyMap (body ), path , matchingRules , generators )
135
+ _ , body , matchingRules = buildPactPartV2 (k .String (), v .Interface (), copyMap (body ), path , matchingRules )
136
136
} else {
137
- _ , body [key ], matchingRules , generators = buildPactPart (k .String (), v .Interface (), entry , path , matchingRules , generators )
137
+ _ , body [key ], matchingRules = buildPactPartV2 (k .String (), v .Interface (), entry , path , matchingRules )
138
138
}
139
139
}
140
140
141
- return path , body , matchingRules , generators
141
+ return path , body , matchingRules
142
+ }
143
+
144
+ func buildPartV2 (value interface {}, path string ) (map [string ]interface {}, rule ) {
145
+ _ , o , matchingRules := buildPactPartV2 ("" , value , make (object ), path , make (rule ))
146
+
147
+ return o , matchingRules
142
148
}
143
149
144
- // Recurse the Matcher tree and buildPactPart up an example body and set of matchers for
150
+ // Recurse the Matcher tree and buildPactPartV2 up an example body and set of matchers for
145
151
// the Pact file. Ideally this stays as a pure function, but probably might need
146
152
// to store matchers externally.
147
153
//
@@ -153,12 +159,10 @@ func recurseMapType(key string, value interface{}, body map[string]interface{},
153
159
// - body => Current state of the body map to be built up (body will be the returned Pact body for serialisation)
154
160
// - path => Path to the current key
155
161
// - matchingRules => Current set of matching rules (matching rules will also be serialised into the Pact)
156
- // - generators => Current set of generators rules (generators rules will also be serialised into the Pact)
157
162
//
158
-
159
- // Returns path, body, matchingRules, generators
160
- func buildPactPart (key string , value interface {}, body map [string ]interface {}, path string ,
161
- matchingRules rule , generators rule ) (string , map [string ]interface {}, rule , rule ) {
163
+ // Returns path, body, matchingRules
164
+ func buildPactPartV2 (key string , value interface {}, body map [string ]interface {}, path string ,
165
+ matchingRules rule ) (string , map [string ]interface {}, rule ) {
162
166
log .Println ("[TRACE] generate pact => key:" , key , ", body:" , body , ", value:" , value , ", path:" , path )
163
167
164
168
switch t := value .(type ) {
@@ -181,7 +185,7 @@ func buildPactPart(key string, value interface{}, body map[string]interface{}, p
181
185
minArray := make ([]interface {}, times )
182
186
183
187
builtPath := path + buildPath (key , allListItems )
184
- buildPactPart ("0" , t .GetValue (), arrayMap , builtPath , matchingRules , generators )
188
+ buildPactPartV2 ("0" , t .GetValue (), arrayMap , builtPath , matchingRules )
185
189
log .Println ("[TRACE] generate pact: ArrayMikeLikeMatcher/ArrayMaxLikeMatcher =>" , builtPath )
186
190
matchingRules [path + buildPath (key , "" )] = m .MatchingRule ()
187
191
@@ -205,7 +209,7 @@ func buildPactPart(key string, value interface{}, body map[string]interface{}, p
205
209
// This exists to server the v3.Match() interface
206
210
case structTypeMatcher :
207
211
log .Println ("[TRACE] generate pact: StructTypeMatcher" )
208
- _ , body , matchingRules , generators = recurseMapType (key , t .GetValue ().(StructMatcher ), body , path , matchingRules , generators )
212
+ _ , body , matchingRules = recurseMapType (key , t .GetValue ().(StructMatcher ), body , path , matchingRules )
209
213
210
214
default :
211
215
log .Fatalf ("unexpected matcher (%s) for current specification format (2.0.0)" , t .Type ())
@@ -223,15 +227,15 @@ func buildPactPart(key string, value interface{}, body map[string]interface{}, p
223
227
k := fmt .Sprintf ("%d" , i )
224
228
builtPath := path + buildPath (key , fmt .Sprintf ("%s%d%s" , startList , i , endList ))
225
229
log .Println ("[TRACE] generate pact: []interface{}: recursing into =>" , builtPath )
226
- buildPactPart (k , el , arrayMap , builtPath , matchingRules , generators )
230
+ buildPactPartV2 (k , el , arrayMap , builtPath , matchingRules )
227
231
arrayValues [i ] = arrayMap [k ]
228
232
}
229
233
body [key ] = arrayValues
230
234
231
235
// Map -> Recurse keys (All objects start here!)
232
236
case map [string ]interface {}, MapMatcher , QueryMatcher :
233
237
log .Println ("[TRACE] generate pact: MapMatcher" )
234
- _ , body , matchingRules , generators = recurseMapType (key , t , body , path , matchingRules , generators )
238
+ _ , body , matchingRules = recurseMapType (key , t , body , path , matchingRules )
235
239
236
240
// Primitives (terminal cases)
237
241
default :
@@ -241,7 +245,7 @@ func buildPactPart(key string, value interface{}, body map[string]interface{}, p
241
245
242
246
log .Printf ("[TRACE] generate pact => returning body: %+v\n " , body )
243
247
244
- return path , body , matchingRules , generators
248
+ return path , body , matchingRules
245
249
}
246
250
247
251
// V2 query strings are stored as strings
@@ -256,9 +260,8 @@ func buildPactPart(key string, value interface{}, body map[string]interface{}, p
256
260
// See https://stackoverflow.com/questions/6243051/how-to-pass-an-array-within-a-query-string
257
261
// TODO: allow a specific generator to be provided?
258
262
func buildPactRequestQueryV2 (input map [string ]interface {}, sourceInteraction * InteractionV2 , destInteraction * pactInteractionV2 , options PactSerialisationOptionsV2 ) {
259
- // matching rules already added
260
-
261
263
var parts []string
264
+
262
265
for k , v := range input {
263
266
rt := reflect .TypeOf (v )
264
267
switch rt .Kind () {
0 commit comments