openapi-codegen
openapi-codegen copied to clipboard
handling multiple openapi .yaml files
Hi there,
this works great and i really like the DX it provides. I was wondering how would you handle multiple openapi source files? say your api is split in more than one .yaml file?
do i need to create multiple openapi-codegen.config.ts
files and pass --config [name-of-config-file]
to the npx openapi-codegen gen lmwr
command? or is there another way i should go about this. i don't want to overwrite the fetcher and context files.
cheers, C
This is already handled 😁
You can just re-run openapi-codegen init
to setup as many api as you want, each of them will have a "namespace":
You need to use this namespace to gen the correct, so if you enter myapp
you will do npx openapi-codegen gen myapp
In you example lmwr
is actually one configuration (the key in openapi-codegen.config.ts
) 😉
ok. got it. i thought there must be something. 😄 thanks.
is there also a way to configure it to reuse the fetcher and context? besides doing it manually?
hmm maybe this can help?
https://github.com/networknt/openapi-bundler
oh it is written with java
hmm, https://redocly.com/docs/cli/commands/bundle/
So, if I understood correctly you have one main spec and that spec points to different sub specs with ref path, right?
our api is very big so it is split by domain into separate files. the baseUrl is the same for all, auth is the same for all. there isn't one main spec with subs. just multiple files sharing the same baseUrl
but for our case a "merge .yaml files before use" would be better. because otherwise i'd need to merge the QueryOperation in the context
for now, looks like you can bundle it by redocly cli
can you try to bundle it manually and test it with generated bundled spec? Also looks like we should consider adding support for multiple spec files. I did some research and it looks common enough.
+1 for redocly, we are using the exact same tool in my company to bundle our openapi specs 😁
i get Can't resolve $ref
errors from redocly 🤷🏻♂️
Can you share the trimmed versions of the 2 specs? So I can test.
i cannot unfortunately. will try to investigate on my own why the merging fails. i think it may be that the refs are not namespaced properly and some conflicts appear. thanks though for offering to help out. i really appreciate it.
i hope this doesnt stop you from working on https://github.com/fabien0102/openapi-codegen/issues/102#issuecomment-1260962246