diff --git a/src/commands/generate/models.ts b/src/commands/generate/models.ts index 209a20abf9a..83580214b89 100644 --- a/src/commands/generate/models.ts +++ b/src/commands/generate/models.ts @@ -7,7 +7,7 @@ import { generateModels, Languages, ModelinaArgs } from '@asyncapi/modelina-cli' import { modelsFlags } from '../../core/flags/generate/models.flags'; import { proxyFlags } from 'core/flags/proxy.flags'; import { HttpsProxyAgent } from 'https-proxy-agent'; -import fetch, { RequestInit } from 'node-fetch'; +import fetch, { RequestInit, Response } from 'node-fetch'; export default class Models extends Command { static description = 'Generates typed models'; @@ -27,7 +27,8 @@ export default class Models extends Command { const interactive = !flags['no-interactive']; const proxyHost = flags['proxyHost']; const proxyPort = flags['proxyPort']; - let proxyAgent; + let proxyAgent: HttpsProxyAgent | undefined; + if (proxyHost && proxyPort) { const proxyUrl = `http://${proxyHost}:${proxyPort}`; @@ -43,9 +44,12 @@ export default class Models extends Command { output = parsedArgs.output; } - const customFetch = proxyAgent - ? (url: string, options: RequestInit = {}) => fetch(url, { ...options, agent: proxyAgent }) - : fetch; + const customFetch = (url: string, options: RequestInit = {}): Promise => { + return proxyAgent + ? fetch(url, { ...options, agent: proxyAgent }) + : fetch(url, options); + }; + const inputFile = (await load(file)) || (await load()); const { document, diagnostics ,status } = await parse(this, inputFile, flags as ValidateOptions);