Open slahn opened 1 month ago
Hey, this isn't currently possible, see https://github.com/hey-api/openapi-ts/discussions/444. Are you able to share how you work around this today?
Currently working around this by not using a config file, and having multiple invocations with command line options in package.json
.
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. https://github.com/unjs/c12/issues/92
This is the workaround I'm using. Define multiple config values and switch on an env var.
import { defineConfig } from '@hey-api/openapi-ts';
const APIv1 = defineConfig({
input: 'https://myapi.com/v1/openapi.json',
output: 'api/v1',
client: '@hey-api/client-fetch',
});
const APIv2 = defineConfig({
input: 'https://myapi.com/v2/openapi.json',
output: 'api/v2',
client: '@hey-api/client-fetch',
});
let configExport;
switch (process.env.API_SPEC) {
case "APIv1": {
configExport = APIv1;
break;
}
case "APIv2": {
configExport = APIv2;
break;
}
default:
configExport = APIv1;
}
export default configExport;
Then commands can be run simply with:
API_SPEC=APIv1 npx @hey-api/openapi-ts
Description
Our projects needs clients/models for multiple different OpenAPI specifications.
Is it possible to specify multiple configurations in the config file, or to instruct the CLI to load a specific config file?
If this is already possible, some mention in the documentation would be helpful.