@@ -9,12 +9,11 @@ import { proxyFlags } from '@cli/internal/flags/proxy.flags';
99import specs from '@asyncapi/specs' ;
1010import { convertFlags } from '@cli/internal/flags/convert.flags' ;
1111import { ConversionService } from '@services/convert.service' ;
12+ import { applyProxyToPath } from '@utils/proxy' ;
1213
1314const latestVersion = Object . keys ( specs . schemas ) . pop ( ) as string ;
1415
1516export default class Convert extends Command {
16- static specFile : any ;
17- static metricsMetadata : any = { } ;
1817 static description =
1918 'Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI' ;
2019 private conversionService = new ConversionService ( ) ;
@@ -32,18 +31,15 @@ export default class Convert extends Command {
3231
3332 async run ( ) {
3433 const { args, flags } = await this . parse ( Convert ) ;
35- let filePath = args [ 'spec-file' ] ;
36- const proxyHost = flags [ 'proxyHost' ] ;
37- const proxyPort = flags [ 'proxyPort' ] ;
38- if ( proxyHost && proxyPort ) {
39- const proxyUrl = `http://${ proxyHost } :${ proxyPort } ` ;
40- filePath = `${ filePath } +${ proxyUrl } ` ; // Update filePath with proxyUrl
41- }
34+ const filePath = applyProxyToPath (
35+ args [ 'spec-file' ] ,
36+ flags [ 'proxyHost' ] ,
37+ flags [ 'proxyPort' ]
38+ ) ;
4239
4340 try {
4441 // LOAD FILE
4542 this . specFile = await load ( filePath ) ;
46- // eslint-disable-next-line sonarjs/no-duplicate-string
4743 this . metricsMetadata . to_version = flags [ 'target-version' ] ;
4844 const conversionOptions = {
4945 format : flags . format as 'asyncapi' | 'openapi' | 'postman-collection' ,
@@ -76,20 +72,20 @@ export default class Convert extends Command {
7672 this . log ( result . data . convertedDocument ) ;
7773 }
7874 } catch ( err ) {
79- this . handleError ( err , filePath ?? 'unknown' , flags ) ;
75+ this . handleError ( err , filePath ?? 'unknown' , flags [ 'target-version' ] ) ;
8076 }
8177 }
8278
8379 // Helper function to handle errors
84- private handleError ( err : any , filePath : string , flags : any ) {
80+ private handleError ( err : unknown , filePath : string , targetVersion : string | undefined ) {
8581 if ( err instanceof SpecificationFileNotFound ) {
8682 this . error (
8783 new ValidationError ( {
8884 type : 'invalid-file' ,
8985 filepath : filePath ,
9086 } ) ,
9187 ) ;
92- } else if ( this . specFile ?. toJson ( ) . asyncapi > flags [ 'target-version' ] ) {
88+ } else if ( this . specFile ?. toJson ( ) . asyncapi > ( targetVersion ?? '' ) ) {
9389 this . error (
9490 `The ${ cyan ( filePath ) } file cannot be converted to an older version. Downgrading is not supported.` ,
9591 ) ;
0 commit comments