@@ -31,9 +31,9 @@ function apib2postman(apib, options) {
31
31
const title = category . meta . title ;
32
32
const groups = [ ] ;
33
33
34
- const schemaGroupDir = options . schema + '/' + title ;
35
- if ( ! fs . existsSync ( schemaGroupDir ) ) {
36
- shell . mkdir ( '-p' , schemaGroupDir ) ;
34
+ const contractGroupDir = options . contract + '/' + title ;
35
+ if ( ! fs . existsSync ( contractGroupDir ) ) {
36
+ shell . mkdir ( '-p' , contractGroupDir ) ;
37
37
}
38
38
39
39
category . content
@@ -50,12 +50,12 @@ function apib2postman(apib, options) {
50
50
variables : attributes . variable
51
51
} ;
52
52
53
- const schemaFilePath = schemaGroupDir + '/' + resource . meta . title + '.json' ;
53
+ const contractFilePath = contractGroupDir + '/' + resource . meta . title + '.json' ;
54
54
const actions = parseActions (
55
55
baseAction ,
56
56
resource . content . filter ( x => x . element === 'transition' ) ,
57
57
environment ,
58
- schemaFilePath
58
+ contractFilePath
59
59
) ;
60
60
61
61
addEnvVariables ( environment . values , attributes . envVariable ) ;
@@ -94,7 +94,7 @@ function parsePath(uriTemplate) {
94
94
return decodeURIComponent ( uriTemplate . expand ( params ) ) . split ( '/' ) . slice ( 1 ) ;
95
95
}
96
96
97
- function parseActions ( baseAction , actions , environment , schemaFilePath ) {
97
+ function parseActions ( baseAction , actions , environment , contractFilePath ) {
98
98
return actions . map ( action => {
99
99
const transaction = _ . find ( action . content , x => x . element === 'httpTransaction' ) ;
100
100
const request = parseRequest ( _ . find ( transaction . content , x => x . element === 'httpRequest' ) ) ;
@@ -116,7 +116,17 @@ function parseActions(baseAction, actions, environment, schemaFilePath) {
116
116
addEnvVariables ( environment . values , attributes . envVariable ) ;
117
117
}
118
118
119
- const response = parseResponse ( _ . find ( transaction . content , x => x . element === 'httpResponse' ) , schemaFilePath ) ;
119
+ const resource = newAction . path . join ( '/' ) ;
120
+ const response = parseResponse ( _ . find ( transaction . content , x => x . element === 'httpResponse' ) ) ;
121
+ const contract = {
122
+ resource : resource ,
123
+ queryParameters : newAction . query ,
124
+ request : request ,
125
+ statusCode : response . statusCode ,
126
+ responseHeaders : response . headers ,
127
+ jsonSchema : response . jsonSchema
128
+ }
129
+ fs . writeFileSync ( contractFilePath , JSON . stringify ( contract , null , 2 ) ) ;
120
130
121
131
return _ . merge ( { } , newAction , {
122
132
name : action . meta . title ,
@@ -196,12 +206,12 @@ function parseRequestHeaders(headers) {
196
206
return parseHeaders ( headers . content . filter ( x => x . content . key . content !== 'Authorization' ) ) ;
197
207
}
198
208
199
- function parseResponse ( response , schemaFilePath ) {
209
+ function parseResponse ( response ) {
200
210
return {
201
211
statusCode : response . attributes . statusCode ,
202
212
headers : response . attributes . headers ? parseHeaders ( response . attributes . headers . content ) : { } ,
203
213
body : parseContent ( response . content , 'messageBody' ) . content ,
204
- jsonSchema : parseJsonSchema ( response . content , schemaFilePath ) ,
214
+ jsonSchema : parseJsonSchema ( response . content ) ,
205
215
tests : parseBodyTests ( response . content )
206
216
} ;
207
217
}
@@ -239,11 +249,10 @@ function parseBodyTests(content) {
239
249
return tests [ 1 ] . split ( / \r \n ? | \n / g) ;
240
250
}
241
251
242
- function parseJsonSchema ( content , schemaFilePath ) {
252
+ function parseJsonSchema ( content ) {
243
253
try {
244
254
const schemaJson = parseContent ( content , 'messageBodySchema' ) . content ;
245
255
const schema = JSON . parse ( schemaJson ) ;
246
- fs . writeFileSync ( schemaFilePath , schemaJson ) ;
247
256
if ( schema ) {
248
257
return schema ;
249
258
}
0 commit comments