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
Generating code based on multiple OpenAPI schemas #1056
I am facing a challenge using the library. On the project I am working on, we have several microservices, each of them with its own OpenAPI schema, which means that I have to deal with different .yaml files.
I am not sure if this is possible, but is there any way to declare several inputs instead of just one? kind of:
I was checking the ClientConfig documentation, and it looks like the input property can be an object, but I am doing something wrong because it's not working as I expected.
I would appreciate any guidance.
Thanks a lot in advance!
Reacted by ash89i, francois-duquesne-asl, Kilian Finger, Sean, Andreas Hribar, Greet, Júlio Gori Corradi, Анна Номерова, floleroy59000, Lukas Koeller and 33 more
Hey @frankPairs, it can be an object, but it does not support what you're describing. This should be easy to add though. What's up with the "service1" naming? What's the expected output?
My first intuition is that the files generated from @generated/openapi-schemas/service1/service1.yaml would be within the output folder using the same name. Just following the example describe above, it would look like:
Reacted by floleroy59000, Atomie CHEN and vector-omalyutin
Like said by @frankPairs, i will be very interested by this functionnality because on my project i have several swagger, and i would wish they are classified by input name in output directory.
But actually, I have this issue if i launch the command
npm run openapi
Unexpected error occurred. Unsupported OpenAPI specification: {
while in the documentation, the input type is a string or a Record<string, unknown>;
We also have multiple services we generate clients for. We simply have a base openapi-ts/defineConfig.ts, which prefixes all methods through methodeNameBuilder:
Probably could be a bit smoother by calling them from node or similar, but it works.
Reacted by Kateryna Zviagina, rlagoue, Lukas A. Santiago, ctrhub, Scott Stevens, Shinigami, Lukas Schmelzeisen, Anton Begehr, Max Tropnikov, Thomas P. and 3 more
Reacted by Anonimous, rlagoue, floleroy59000, Cody Bontecou, Shinigami, Pasha Rybenko, Alexander, AbdelzaherAbdelgwad and Martin
This is an essential feature imo. The advantage of OpenAPI is to be able to pull in any api you want and easily use as client in your code base. Having openapi-ts support only one client by default works if you have one backend and a frontend but breaks down as soon as you'd like to use micro services or any combination of openapi apis on your backend as well.
#1056 (comment) is working quite well for me, and sadly this is the reason why I didn't put more energy by contributing to it 😅
You should try that workaround, or you could think about to contribute and open a PR
If you like you can call me to review your PR
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? Now i'm probably going to move on to allowing multiple inputs to one config
@pachecoka can you try the preview in #2602 (comment) and let us know if it works as expected? I wanted to clean up the internals a bit before merging, functionally it should just work already
I tried it out and it works.
Only thing I noticed is that now in the generated code for client/client.gen.ts there is a function called makeSseFn and it makes use of BodyInit. This type was not being found and giving me an error, but adding the following to tsconfig made it work.
Thanks for this feature, it's working. That's my adopted example, as prefixing the methods might still be necessary, but now in a single openapi-ts.config.ts:
Activity
mrlubos commentedon Sep 18, 2024
Hey @frankPairs, it can be an object, but it does not support what you're describing. This should be easy to add though. What's up with the "service1" naming? What's the expected output?
frankPairs commentedon Sep 18, 2024
My first intuition is that the files generated from
@generated/openapi-schemas/service1/service1.yamlwould be within the output folder using the same name. Just following the example describe above, it would look like:robert-lore commentedon Sep 24, 2024
I'd like to do something similar, but was thinking something like this would work, and found out it doesn't:
floleroy59000 commentedon Oct 5, 2024
Like said by @frankPairs, i will be very interested by this functionnality because on my project i have several swagger, and i would wish they are classified by input name in output directory.
But actually, I have this issue if i launch the command
Unexpected error occurred. Unsupported OpenAPI specification: {while in the documentation, the input type is a string or a Record<string, unknown>;
On project openapi-typescript-codegen
https://github.com/ferdikoomen/openapi-typescript-codegen/tree/main?tab=readme-ov-file
I was not bothered because I was running X commands (in the package.json) for X swagger to get the data generated.
openapi -i http://localhost:8080/api/xxxx/swagger.json -o src/api/xxxx --client axios --indent 2KiwiKilian commentedon Nov 18, 2024
We also have multiple services we generate clients for. We simply have a base
openapi-ts/defineConfig.ts, which prefixes all methods throughmethodeNameBuilder:Then we have separate config file for each service,
openapi-ts/management.config.ts:And
openapi-ts/analysis.config.ts:Then we run them like:
Probably could be a bit smoother by calling them from node or similar, but it works.
Kibo007 commentedon Jan 22, 2025
I made script
then just call script and will generate multiple types
abegehr commentedon May 21, 2025
This is an essential feature imo. The advantage of OpenAPI is to be able to pull in any api you want and easily use as client in your code base. Having openapi-ts support only one client by default works if you have one backend and a frontend but breaks down as soon as you'd like to use micro services or any combination of openapi apis on your backend as well.
rick1290 commentedon Jun 11, 2025
any update on this?
Shinigami92 commentedon Jun 12, 2025
#1056 (comment) is working quite well for me, and sadly this is the reason why I didn't put more energy by contributing to it 😅
You should try that workaround, or you could think about to contribute and open a PR
If you like you can call me to review your PR
mrlubos 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? Now i'm probably going to move on to allowing multiple inputs to one config
frankPairs commentedon Sep 11, 2025
hey @carson2222 ! I think your proposal looks nice to solve the problem that I described on this issue.
carson2222 commentedon Sep 11, 2025
I'm glad you like it. This and some more config features will be added soon once the #2602 gets merged 🫡
pachecoka commentedon Oct 2, 2025
Hey @carson2222 any idea on when this will get merged? Would love to use this!
mrlubos commentedon Oct 2, 2025
@pachecoka can you try the preview in #2602 (comment) and let us know if it works as expected? I wanted to clean up the internals a bit before merging, functionally it should just work already
pachecoka commentedon Oct 2, 2025
Hey @mrlubos,
I tried it out and it works.
Only thing I noticed is that now in the generated code for
client/client.gen.tsthere is a function calledmakeSseFnand it makes use ofBodyInit. This type was not being found and giving me an error, but adding the following totsconfigmade it work.mrlubos commentedon Oct 6, 2025
This will be available in the next release. Looking forward to your feedback!
KiwiKilian commentedon Oct 27, 2025
Thanks for this feature, it's working. That's my adopted example, as prefixing the methods might still be necessary, but now in a single
openapi-ts.config.ts:We run this with
openapi-ts && prettier --write './src/modules/api/**/*.ts' --log-level errordue to #2200. Also looking forward to #2579.mrlubos commentedon Oct 27, 2025
@KiwiKilian this is starting to look clean!