-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
27 lines (23 loc) · 890 Bytes
/
convert.js
File metadata and controls
27 lines (23 loc) · 890 Bytes
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
const p2o = require('postman-to-openapi');
const fs = require('fs');
const path = require('path');
const inputPath = path.join(__dirname, 'collection.json');
const tempPath = path.join(__dirname, 'clean_collection.json');
const outputPath = path.join(__dirname, 'docs', 'openapi.yaml');
try {
const collectionData = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
const actualCollection = collectionData.collection || collectionData;
fs.writeFileSync(tempPath, JSON.stringify(actualCollection, null, 2));
p2o(tempPath, outputPath)
.then(result => {
console.log(`OpenAPI spec generated successfully at ${outputPath}`);
fs.unlinkSync(tempPath); // Clean up
})
.catch(err => {
console.error('Error during conversion:', err);
process.exit(1);
});
} catch (err) {
console.error('Error reading collection.json:', err);
process.exit(1);
}