Skip to content

Commit

Permalink
updated models.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
IITI-tushar committed Jan 18, 2025
1 parent 801e52d commit 16fe0e7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/commands/generate/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<string> | undefined;


if (proxyHost && proxyPort) {
const proxyUrl = `http://${proxyHost}:${proxyPort}`;
Expand All @@ -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<Response> => {
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);
Expand Down

0 comments on commit 16fe0e7

Please sign in to comment.