|
| 1 | +const axios = require("axios"); |
| 2 | +const Converter = require("openapi-to-postmanv2"); |
1 | 3 |
|
2 | | -const axios = require('axios'); |
3 | | -const Converter = require('openapi-to-postmanv2'); |
4 | | - |
5 | | -const POSTMAN_COLLECTION_ID = '15964941-fdc9fd1f-d7bc-4f7e-b5ce-9189dbcbb81d'; |
| 4 | +const POSTMAN_COLLECTION_ID = |
| 5 | + process.env.POSTMAN_COLLECTION_ID || |
| 6 | + "15964941-fdc9fd1f-d7bc-4f7e-b5ce-9189dbcbb81d"; |
6 | 7 | const POSTMAN_API_KEY = process.env.POSTMAN_API_KEY; |
7 | 8 |
|
8 | | -const openapiUrl = 'https://api.svix.com/api/v1/openapi.json'; |
| 9 | +const openapiUrl = "https://api.svix.com/api/v1/openapi.json"; |
9 | 10 |
|
10 | 11 | const conversionOptions = { |
11 | | - 'folderStrategy': 'tags' |
| 12 | + folderStrategy: "tags", |
12 | 13 | }; |
13 | 14 |
|
14 | | -const error = function(msg) { |
| 15 | +const error = function (msg) { |
15 | 16 | console.error(msg); |
16 | 17 | process.exit(1); |
17 | 18 | }; |
18 | 19 |
|
19 | 20 | const update_collection = async (collection) => { |
20 | | - const res = await axios.put( |
| 21 | + await axios.put( |
21 | 22 | `https://api.getpostman.com/collections/${POSTMAN_COLLECTION_ID}`, |
22 | 23 | { |
23 | | - "collection": collection |
| 24 | + collection: collection, |
24 | 25 | }, |
25 | 26 | { |
26 | | - headers: { "x-api-key": POSTMAN_API_KEY } |
| 27 | + headers: { "x-api-key": POSTMAN_API_KEY }, |
| 28 | + validateStatus: function (status) { |
| 29 | + return status < 300; |
| 30 | + }, |
27 | 31 | }, |
28 | 32 | ); |
29 | 33 | }; |
30 | 34 |
|
31 | 35 | (async () => { |
32 | 36 | try { |
33 | | - |
34 | 37 | const res = await axios.get(openapiUrl); |
35 | 38 | const openapiData = res.data; |
36 | 39 |
|
37 | 40 | let collection; |
38 | | - Converter.convert({ type: 'json', data: openapiData }, |
39 | | - conversionOptions, (err, conversionResult) => { |
| 41 | + Converter.convert( |
| 42 | + { type: "json", data: openapiData }, |
| 43 | + conversionOptions, |
| 44 | + (_err, conversionResult) => { |
40 | 45 | if (!conversionResult.result) { |
41 | 46 | error(`Could not convert: ${conversionResult.reason}`); |
42 | 47 | } |
43 | 48 | collection = conversionResult.output[0].data; |
44 | | - } |
| 49 | + }, |
45 | 50 | ); |
46 | 51 |
|
47 | 52 | await update_collection(collection); |
48 | | - |
49 | 53 | } catch (e) { |
50 | 54 | if (e.response !== undefined) { |
51 | 55 | error(e.response); |
|
0 commit comments