-
Notifications
You must be signed in to change notification settings - Fork 3
/
transform.js
60 lines (52 loc) · 1.87 KB
/
transform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const {
Response,
Route,
} = require("./lib/models/");
const transformPostmanToMockoon = ({ postman, mockoon, env }) => {
env.item.uuid = postman.info._postman_id;
postman.item.forEach((collection) => {
collection.item.forEach((r_data) => {
if (r_data.request && r_data.responses && r_data.responses.length == 0) {
// console.warn("Found request-only item, skipping...");
} else {
if (r_data.response) {
r_data.responses = r_data.response;
}
let route = Route();
route.documentation = r_data.name;
route.method = r_data.request.method.toLowerCase();
let url = r_data.request.url;
route.endpoint = (typeof url == "string" ?
url
: (
typeof url.path == "string" ?
url.path
: url.path.join("/")
)
);
if (r_data.responses && r_data.responses.length > 0) {
r_data.responses.forEach((r) => {
let resp = Response();
if (r.code) {
resp.statusCode = r.code.toString();
}
if (r.header) {
resp.headers = r.header;
}
if (r.body) {
resp.body = r.body;
}
route.responses.push(resp);
});
} else {
route.responses.push(Response())
}
env.item.routes.push(route);
}
});
});
mockoon.data.push(env);
}
module.exports = {
transformPostmanToMockoon
}