Skip to content

Commit ab01842

Browse files
committed
chore: Update package name to penify-oapi-codegen and improve command-line argument handling
1 parent f0cc5fc commit ab01842

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "openapi-code-gen",
2+
"name": "penify-oapi-codegen",
33
"version": "1.0.0",
44
"description": "A JavaScript library to convert OpenAPI schema to Postman collection and generate sample code.",
55
"main": "src/index.js",

src/index.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,40 @@
33
const OpenAPIHelper = require('./OpenAPIHelper');
44
const path = require('path');
55
const { v4: uuidv4 } = require('uuid');
6+
const yargs = require('yargs/yargs');
7+
const { hideBin } = require('yargs/helpers');
68

7-
// Get the OpenAPI JSON path from the command-line arguments
8-
const openAPIPath = process.argv[2];
9-
const language = process.argv[3] || null; // Language input (optional)
10-
const variant = process.argv[4] || null; // Variant input (optional)
9+
// Parse command-line arguments
10+
const argv = yargs(hideBin(process.argv))
11+
.usage('Usage: penify-oapi-codegen -s <source> -l <language> -v <variant> -o <output>')
12+
.option('s', {
13+
alias: 'source',
14+
describe: 'Path to the OpenAPI JSON file',
15+
type: 'string',
16+
demandOption: true
17+
})
18+
.option('l', {
19+
alias: 'language',
20+
describe: 'Language input (optional)',
21+
type: 'string'
22+
})
23+
.option('v', {
24+
alias: 'variant',
25+
describe: 'Variant input (optional)',
26+
type: 'string'
27+
})
28+
.option('o', {
29+
alias: 'output',
30+
describe: 'Output file path (optional)',
31+
type: 'string'
32+
})
33+
.help()
34+
.argv;
35+
36+
const openAPIPath = argv.s;
37+
const language = argv.l || null;
38+
const variant = argv.v || null;
39+
const outputAPIPath = argv.o || path.resolve(`${path.basename(openAPIPath)}_with_code.json`);
1140

1241
if (!openAPIPath) {
1342
console.error('Please provide the path to the OpenAPI JSON file.');
@@ -19,7 +48,7 @@ const file_name = path.basename(resolvedOpenAPIPath);
1948
const guid = uuidv4();
2049

2150
const postmanOutputPath = path.resolve(`/tmp/openapi_schema_postman_${guid}.json`);
22-
const outputAPIPath = path.resolve(`${file_name}_with_code.json`);
51+
2352
console.log("Executing step 1.");
2453
OpenAPIHelper.convertOpenAPIToPostman(resolvedOpenAPIPath, postmanOutputPath);
2554
console.log("Executing step 2.");

0 commit comments

Comments
 (0)