···11+#!/usr/bin/env node
22+33+'use strict';
44+55+import { program } from 'commander';
66+77+import { createClient } from '~/index';
88+99+import pkg from '../package.json' assert { type: 'json' };
1010+1111+const params = program
1212+ .name(Object.keys(pkg.bin)[0]!)
1313+ .usage('[options]')
1414+ .version(pkg.version)
1515+ .option(
1616+ '-c, --client <value>',
1717+ 'HTTP client to generate [@hey-api/client-axios, @hey-api/client-fetch, @hey-api/client-next, @hey-api/client-nuxt, legacy/angular, legacy/axios, legacy/fetch, legacy/node, legacy/xhr]',
1818+ )
1919+ .option('-d, --debug', 'Set log level to debug')
2020+ .option('--dry-run [value]', 'Skip writing files to disk?')
2121+ .option(
2222+ '-e, --experimental-parser [value]',
2323+ 'Opt-in to the experimental parser?',
2424+ )
2525+ .option('-f, --file [value]', 'Path to the config file')
2626+ .option(
2727+ '-i, --input <value>',
2828+ 'OpenAPI specification (path, url, or string content)',
2929+ )
3030+ .option('-l, --logs [value]', 'Logs folder')
3131+ .option('-o, --output <value>', 'Output folder')
3232+ .option('-p, --plugins [value...]', "List of plugins you'd like to use")
3333+ .option(
3434+ '--base [value]',
3535+ 'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value',
3636+ )
3737+ .option('-s, --silent', 'Set log level to silent')
3838+ .option(
3939+ '--no-log-file',
4040+ 'Disable writing a log file. Works like --silent but without suppressing console output',
4141+ )
4242+ .option(
4343+ '-w, --watch [value]',
4444+ 'Regenerate the client when the input file changes?',
4545+ )
4646+ .option('--exportCore [value]', 'DEPRECATED. Write core files to disk')
4747+ .option('--name <value>', 'DEPRECATED. Custom client class name')
4848+ .option('--request <value>', 'DEPRECATED. Path to custom request file')
4949+ .option(
5050+ '--useOptions [value]',
5151+ 'DEPRECATED. Use options instead of arguments?',
5252+ )
5353+ .parse(process.argv)
5454+ .opts();
5555+5656+const stringToBoolean = (value: any) => {
5757+ if (value === 'true') {
5858+ return true;
5959+ }
6060+ if (value === 'false') {
6161+ return false;
6262+ }
6363+ return value;
6464+};
6565+6666+const processParams = (obj: any, booleanKeys: any) => {
6767+ for (const key of booleanKeys) {
6868+ const value = obj[key];
6969+ if (typeof value === 'string') {
7070+ const parsedValue = stringToBoolean(value);
7171+ delete obj[key];
7272+ obj[key] = parsedValue;
7373+ }
7474+ }
7575+ if (obj.file) {
7676+ obj.configFile = obj.file;
7777+ }
7878+ return obj;
7979+};
8080+8181+async function start() {
8282+ let userConfig;
8383+8484+ try {
8585+ userConfig = processParams(params, [
8686+ 'dryRun',
8787+ 'logFile',
8888+ 'experimentalParser',
8989+ 'exportCore',
9090+ 'useOptions',
9191+ ]);
9292+9393+ if (params.plugins === true) {
9494+ userConfig.plugins = [];
9595+ } else if (params.plugins) {
9696+ userConfig.plugins = params.plugins;
9797+ } else if (userConfig.client) {
9898+ userConfig.plugins = ['@hey-api/typescript', '@hey-api/sdk'];
9999+ }
100100+101101+ if (userConfig.client) {
102102+ userConfig.plugins.push(userConfig.client);
103103+ delete userConfig.client;
104104+ }
105105+106106+ userConfig.logs = userConfig.logs
107107+ ? {
108108+ path: userConfig.logs,
109109+ }
110110+ : {};
111111+112112+ if (userConfig.debug || stringToBoolean(process.env.DEBUG)) {
113113+ userConfig.logs.level = 'debug';
114114+ } else if (userConfig.silent) {
115115+ userConfig.logs.level = 'silent';
116116+ }
117117+118118+ userConfig.logs.file = userConfig.logFile;
119119+ delete userConfig.logFile;
120120+121121+ if (typeof params.watch === 'string') {
122122+ userConfig.watch = Number.parseInt(params.watch, 10);
123123+ }
124124+125125+ if (!Object.keys(userConfig.logs).length) {
126126+ delete userConfig.logs;
127127+ }
128128+129129+ const context = await createClient(userConfig);
130130+ if (
131131+ !context[0]?.config.input.some(
132132+ (input) => input.watch && input.watch.enabled,
133133+ )
134134+ ) {
135135+ process.exit(0);
136136+ }
137137+ } catch {
138138+ process.exit(1);
139139+ }
140140+}
141141+142142+start();
+1-1
packages/openapi-ts/src/ir/context.ts
···14141515import type { IR } from './types';
16161717-export class IRContext<Spec extends Record<string, any> = any> {
1717+export class Context<Spec extends Record<string, any> = any> {
1818 /**
1919 * Configuration for parsing and generating the output. This
2020 * is a mix of user-provided and default values.
+1-1
packages/openapi-ts/src/ir/types.d.ts
···44 ServerObject,
55} from '~/openApi/3.1.x/types/spec';
6677-import type { IRContext } from './context';
77+import type { Context as IRContext } from './context';
88import type { IRMediaType } from './mediaType';
991010interface IRBodyObject {
+2-2
packages/openapi-ts/src/openApi/index.ts
···11import { satisfies } from '~/config/utils/package';
22-import { IRContext } from '~/ir/context';
22+import { Context } from '~/ir/context';
33import type { IR } from '~/ir/types';
44import { parseV2_0_X } from '~/openApi/2.0.x';
55import { parseV3_0_X } from '~/openApi/3.0.x';
···7474 logger: Logger;
7575 spec: unknown;
7676}): IR.Context | undefined => {
7777- const context = new IRContext({
7777+ const context = new Context({
7878 config,
7979 dependencies,
8080 logger,