You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multiple configurations/specifying a configuration file #564
I looked into this and the current blocker is that c12 does not support it. I'll see if I get a reply in the issue and if not, I will fork that package and add support. unjs/c12#92
import{execSync}from'child_process';import{Command}from'commander';import{existsSync,unlinkSync,writeFileSync}from'fs';typeGenerateConfigOptions={input: string;
outputPath: string;
clientName: string;
httpClient: 'fetch'|'axios';enumType?: 'typescript'|'javascript';
asClass: boolean;};functiongenerateConfig(options: GenerateConfigOptions){consttypesConfig=options.enumType
? `types: { enums: '${options.enumType}' },`
: '';return` import { defineConfig } from '@hey-api/openapi-ts'; export default defineConfig({ input: '${options.input}', output: { path: '${options.outputPath}', format: 'prettier', lint: 'eslint', }, name: '${options.clientName}', client: '${options.httpClient}',${typesConfig} services: { asClass: ${options.asClass}, }, }); `;}constprogram=newCommand();program.requiredOption('--input <urlOrPath>','Path to the input OpenAPI specification file',).requiredOption('--client-name <string>','Name of the client to generate').requiredOption('--output-path <path>','Directory path where the generated client will be saved',).requiredOption('--http-client <httpClient>','HTTP client to use (fetch or axios)',(value)=>{if(!['fetch','axios'].includes(value)){thrownewError('Invalid HTTP client. Must be "fetch" or "axios".');}returnvalue;},).requiredOption('--as-class <asClass>','Generate services as classes if true',(value)=>{if(!['true','false'].includes(value)){thrownewError('Invalid value for asClass. Must be either true or false.',);}returnBoolean(value==='true');},).option('--enum-type <enumType>','Type of enums to generate (typescript or javascript) (optional)',(value)=>{if(value!=='typescript'&&value!=='javascript'){thrownewError('Invalid enum type. Must be either "typescript" or "javascript".',);}returnvalue;},);program.parse(process.argv);constoptions=program.opts()asGenerateConfigOptions;constconfigFilePath='./openapi-ts.config.ts';if(existsSync(configFilePath)){try{unlinkSync(configFilePath);console.log(`Existing file ${configFilePath} has been removed.`);}catch(error){}}constgeneratedConfig=generateConfig(options);try{writeFileSync(configFilePath,generatedConfig);console.log(`Configuration file generated at ${configFilePath}`);try{execSync('yarn openapi-ts',{stdio: 'inherit'});console.log('OpenAPI client generated successfully.');}catch(error){console.error('Error generating OpenAPI client:',error);unlinkSync(configFilePath);process.exit(1);}unlinkSync(configFilePath);}catch(error){console.error(`Error writing to file ${configFilePath}:`,error);unlinkSync(configFilePath);process.exit(1);}
If the openapi-ts cli was 1:1 with the config options in openapi-ts.config.ts, this issue won't be relevant anymore. So maybe the openapi-ts cli flags can be generated by the config? Maybe its worth looking into it instead of waiting for c12 to add multi config
Activity
mrlubos commentedon May 13, 2024
Hey, this isn't currently possible, see #444. Are you able to share how you work around this today?
slahn commentedon May 13, 2024
Currently working around this by not using a config file, and having multiple invocations with command line options in
package.json.mrlubos commentedon May 15, 2024
I looked into this and the current blocker is that c12 does not support it. I'll see if I get a reply in the issue and if not, I will fork that package and add support. unjs/c12#92
ecline123 commentedon Jun 26, 2024
This is the workaround I'm using. Define multiple config values and switch on an env var.
Then commands can be run simply with:
utajum commentedon Jul 12, 2024
Our solution
openapi-generator.tsTo use it:
If the
openapi-tscli was 1:1 with the config options inopenapi-ts.config.ts, this issue won't be relevant anymore. So maybe theopenapi-tscli flags can be generated by the config? Maybe its worth looking into it instead of waiting for c12 to add multi configmrlubos commentedon Aug 31, 2025
Hey all, @carson2222 will be looking at this feature, he'll be your point of contact for getting this over the finish line 🐎
carson2222 commentedon Sep 4, 2025
I'm currently handling the multi-config feature. I added support for an array of objects to defineConfig function. Would this cover all your needs?
mrlubos commentedon Oct 6, 2025
This will be available in the next release. Looking forward to your feedback!