33const OpenAPIHelper = require ( './OpenAPIHelper' ) ;
44const path = require ( 'path' ) ;
55const { 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
1241if ( ! openAPIPath ) {
1342 console . error ( 'Please provide the path to the OpenAPI JSON file.' ) ;
@@ -19,7 +48,7 @@ const file_name = path.basename(resolvedOpenAPIPath);
1948const guid = uuidv4 ( ) ;
2049
2150const postmanOutputPath = path . resolve ( `/tmp/openapi_schema_postman_${ guid } .json` ) ;
22- const outputAPIPath = path . resolve ( ` ${ file_name } _with_code.json` ) ;
51+
2352console . log ( "Executing step 1." ) ;
2453OpenAPIHelper . convertOpenAPIToPostman ( resolvedOpenAPIPath , postmanOutputPath ) ;
2554console . log ( "Executing step 2." ) ;
0 commit comments