From e5f17af12e5abd404356266e3e8e253ffb1be4f0 Mon Sep 17 00:00:00 2001 From: IITI-tushar <019saxenatushar@gmail.com> Date: Sat, 18 Jan 2025 12:54:11 +0530 Subject: [PATCH] updated models.ts --- src/commands/generate/models.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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);