11#!/usr/bin/env node
2+ /* eslint-disable no-console */
23
34import { Command } from 'commander' ;
45import { promises as fs } from 'fs' ;
@@ -8,6 +9,18 @@ import { WorkflowAnalyzer } from '../core/workflow-analyzer';
89import { OpenAPIGenerator } from '../core/openapi-generator' ;
910import { GenerationConfig , ServerConfig } from '../types/config' ;
1011import { toValue } from '@speclynx/apidom-core' ;
12+ import { stringify as yamlStringify } from 'yaml' ;
13+
14+ interface CliOptions {
15+ output ? : string ;
16+ format ? : string ;
17+ openapiVersion: string ;
18+ title ? : string ;
19+ versionOverride ? : string ;
20+ description ? : string ;
21+ server: string [ ] ;
22+ responseCode ? : number ;
23+ }
1124
1225const program = new Command ( ) ;
1326
@@ -24,7 +37,7 @@ program
2437 . option ( '--description <description>' , 'Override the OpenAPI description' )
2538 . option ( '--server <url>' , 'Add a server URL (can be used multiple times)' , collectServers , [ ] )
2639 . option ( '--response-code <code>' , 'HTTP response code for successful workflow execution (default: 200)' , parseInt )
27- . action ( async ( arazzoFile : string , options : any ) => {
40+ . action ( async ( arazzoFile : string , options : CliOptions ) => {
2841 try {
2942 await convertArazzoToOpenAPI ( arazzoFile , options ) ;
3043 } catch ( error ) {
@@ -50,7 +63,7 @@ function isRemoteUrl(url: string): boolean {
5063/**
5164 * Main conversion function
5265 */
53- async function convertArazzoToOpenAPI ( arazzoFile : string , options : any ) : Promise < void > {
66+ async function convertArazzoToOpenAPI ( arazzoFile : string , options : CliOptions ) : Promise < void > {
5467 let arazzoPath : string ;
5568
5669 // Check if input is a remote URL or local file
@@ -79,9 +92,11 @@ async function convertArazzoToOpenAPI(arazzoFile: string, options: any): Promise
7992 const workflows = analyzer . analyzeAllWorkflows ( document ) ;
8093 console . log ( `✓ Analyzed ${ workflows . length } workflow(s)` ) ;
8194
95+ // Determine output format
96+ const outputFormat : 'json' | 'yaml' = ( options . format as 'json' | 'yaml' ) || detectedFormat ;
97+
8298 // Determine output path
83- const outputPath = options . output || deriveOutputPath ( arazzoPath , options . format || detectedFormat ) ;
84- const outputFormat = options . format || detectedFormat ;
99+ const outputPath = options . output || deriveOutputPath ( arazzoPath , outputFormat ) ;
85100
86101 // Convert servers from CLI
87102 const servers : ServerConfig [ ] = options . server . map ( ( url : string ) => ( {
@@ -143,7 +158,7 @@ function deriveOutputPath(inputPath: string, format: 'json' | 'yaml'): string {
143158 * Write OpenAPI document to file in specified format
144159 */
145160async function writeOpenAPIDocument (
146- openapi : any ,
161+ openapi : unknown ,
147162 outputPath : string ,
148163 format : 'json' | 'yaml'
149164) : Promise < void > {
@@ -154,10 +169,8 @@ async function writeOpenAPIDocument(
154169 if ( format === 'json' ) {
155170 content = JSON . stringify ( openapiObj , null , 2 ) ;
156171 } else {
157- // For YAML, use a simple serialization approach
158- // In Phase 4, we can enhance this with proper YAML library
159- const yaml = require ( 'yaml' ) ;
160- content = yaml . stringify ( openapiObj , {
172+ // For YAML, use yaml library
173+ content = yamlStringify ( openapiObj , {
161174 indent : 2 ,
162175 lineWidth : 0 ,
163176 minContentWidth : 0 ,
0 commit comments