openapi-to-postman-complete 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +131 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Caio Pizzol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OpenAPI to Postman Complete CLI
|
|
4
|
+
* Command-line tool for converting OpenAPI specs to production-ready Postman collections
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
7
|
+
import { enrichCollection } from '@openapi-to-postman-complete/core';
|
|
8
|
+
// @ts-expect-error - openapi-to-postmanv2 doesn't have types
|
|
9
|
+
import Converter from 'openapi-to-postmanv2';
|
|
10
|
+
function showHelp() {
|
|
11
|
+
console.log(`
|
|
12
|
+
OpenAPI to Postman Complete - Complete OpenAPI to Postman converter
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
openapi-to-postman-complete <input> <config.yaml> [options]
|
|
16
|
+
|
|
17
|
+
Arguments:
|
|
18
|
+
input OpenAPI spec (*.yaml, *.json) or Postman collection (*.json)
|
|
19
|
+
config.yaml Enrichment configuration YAML file
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
-o, --output Output file path (default: enriched-collection.json)
|
|
23
|
+
-h, --help Show this help message
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
# From OpenAPI spec
|
|
27
|
+
openapi-to-postman-complete api.yaml config.yaml -o collection.json
|
|
28
|
+
|
|
29
|
+
# From existing Postman collection
|
|
30
|
+
openapi-to-postman-complete collection.json config.yaml -o enriched.json
|
|
31
|
+
|
|
32
|
+
For more information, visit: https://github.com/caiopizzol/openapi-to-postman-complete
|
|
33
|
+
`);
|
|
34
|
+
}
|
|
35
|
+
async function convertOpenApiToPostman(inputPath) {
|
|
36
|
+
const openApiSpec = readFileSync(inputPath, 'utf8');
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
Converter.convert({ type: 'string', data: openApiSpec }, {}, (err, result) => {
|
|
39
|
+
if (err) {
|
|
40
|
+
reject(err);
|
|
41
|
+
}
|
|
42
|
+
else if (!result.result) {
|
|
43
|
+
reject(new Error(result.reason || 'Conversion failed'));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
resolve(result.output[0].data);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function isOpenApiFile(path) {
|
|
52
|
+
return path.endsWith('.yaml') || path.endsWith('.yml');
|
|
53
|
+
}
|
|
54
|
+
async function main() {
|
|
55
|
+
const args = process.argv.slice(2);
|
|
56
|
+
// Show help
|
|
57
|
+
if (args.length === 0 || args.includes('-h') || args.includes('--help')) {
|
|
58
|
+
showHelp();
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
// Parse arguments
|
|
62
|
+
const inputPath = args[0];
|
|
63
|
+
const configPath = args[1];
|
|
64
|
+
let outputPath = 'enriched-collection.json';
|
|
65
|
+
// Check for output flag
|
|
66
|
+
const outputIndex = args.findIndex((arg) => arg === '-o' || arg === '--output');
|
|
67
|
+
if (outputIndex !== -1 && args[outputIndex + 1]) {
|
|
68
|
+
outputPath = args[outputIndex + 1];
|
|
69
|
+
}
|
|
70
|
+
// Validate arguments
|
|
71
|
+
if (!inputPath || !configPath) {
|
|
72
|
+
console.error('❌ Error: Both input and config file paths are required\n');
|
|
73
|
+
showHelp();
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
console.log('🚀 OpenAPI to Postman Complete\n');
|
|
78
|
+
let collection;
|
|
79
|
+
// Check if input is OpenAPI or Postman collection
|
|
80
|
+
if (isOpenApiFile(inputPath)) {
|
|
81
|
+
console.log(`📝 Converting OpenAPI spec: ${inputPath}`);
|
|
82
|
+
collection = await convertOpenApiToPostman(inputPath);
|
|
83
|
+
console.log(`✅ Converted to Postman collection\n`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log(`📖 Loading Postman collection: ${inputPath}`);
|
|
87
|
+
const collectionJson = readFileSync(inputPath, 'utf8');
|
|
88
|
+
collection = JSON.parse(collectionJson);
|
|
89
|
+
console.log(`✅ Loaded collection with ${countRequests(collection)} requests\n`);
|
|
90
|
+
}
|
|
91
|
+
// Enrich collection
|
|
92
|
+
console.log(`⚙️ Loading config: ${configPath}`);
|
|
93
|
+
const enriched = enrichCollection(collection, configPath);
|
|
94
|
+
console.log(`✅ Collection enriched to ${countRequests(enriched)} requests\n`);
|
|
95
|
+
// Save enriched collection
|
|
96
|
+
console.log(`💾 Saving to: ${outputPath}`);
|
|
97
|
+
writeFileSync(outputPath, JSON.stringify(enriched, null, 2));
|
|
98
|
+
console.log(`✅ Saved successfully\n`);
|
|
99
|
+
console.log('🎉 Done! Your enriched Postman collection is ready.');
|
|
100
|
+
console.log('\nNext steps:');
|
|
101
|
+
console.log('1. Import the collection into Postman');
|
|
102
|
+
console.log('2. Set up your environment variables');
|
|
103
|
+
console.log('3. Start testing your API!\n');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('❌ Error:', error instanceof Error ? error.message : String(error));
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Count total requests in a collection
|
|
112
|
+
*/
|
|
113
|
+
function countRequests(collection) {
|
|
114
|
+
let count = 0;
|
|
115
|
+
function walk(items) {
|
|
116
|
+
if (!items)
|
|
117
|
+
return;
|
|
118
|
+
items.forEach((item) => {
|
|
119
|
+
if (item.request) {
|
|
120
|
+
count++;
|
|
121
|
+
}
|
|
122
|
+
else if (item.item) {
|
|
123
|
+
walk(item.item);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
walk(collection.item);
|
|
128
|
+
return count;
|
|
129
|
+
}
|
|
130
|
+
// Run CLI
|
|
131
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openapi-to-postman-complete",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Complete OpenAPI to Postman converter with filtering, descriptions, examples, variables, and auto-generated tests",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openapi",
|
|
7
|
+
"postman",
|
|
8
|
+
"swagger",
|
|
9
|
+
"api",
|
|
10
|
+
"converter",
|
|
11
|
+
"collection",
|
|
12
|
+
"complete",
|
|
13
|
+
"production-ready",
|
|
14
|
+
"testing",
|
|
15
|
+
"examples",
|
|
16
|
+
"variables",
|
|
17
|
+
"rest-api",
|
|
18
|
+
"postman-collection",
|
|
19
|
+
"openapi-spec"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"bin": {
|
|
23
|
+
"openapi-to-postman-complete": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"openapi-to-postmanv2": "^5.5.0",
|
|
30
|
+
"@openapi-to-postman-complete/core": "0.0.0-development",
|
|
31
|
+
"@openapi-to-postman-complete/shared": "0.0.0-development"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@anolilab/semantic-release-pnpm": "^3.0.0",
|
|
35
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
36
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
37
|
+
"@semantic-release/git": "^10.0.1",
|
|
38
|
+
"@semantic-release/github": "^12.0.2",
|
|
39
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
40
|
+
"@types/node": "^24.10.1",
|
|
41
|
+
"semantic-release": "^25.0.2",
|
|
42
|
+
"tsx": "^4.20.6",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20.0.0"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/caiopizzol/openapi-to-postman-complete.git",
|
|
51
|
+
"directory": "packages/cli"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/caiopizzol/openapi-to-postman-complete/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/caiopizzol/openapi-to-postman-complete#readme",
|
|
57
|
+
"author": "Caio Pizzol",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "tsx src/index.ts",
|
|
64
|
+
"build": "tsc",
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"prepublish": "pnpm build"
|
|
67
|
+
}
|
|
68
|
+
}
|