openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

handling multiple openapi .yaml files

Open cezarneaga opened this issue 2 years ago • 13 comments

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

cezarneaga avatar Sep 28 '22 11:09 cezarneaga

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":

image

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) 😉

fabien0102 avatar Sep 28 '22 11:09 fabien0102

ok. got it. i thought there must be something. 😄 thanks.

cezarneaga avatar Sep 28 '22 12:09 cezarneaga

is there also a way to configure it to reuse the fetcher and context? besides doing it manually?

cezarneaga avatar Sep 28 '22 13:09 cezarneaga

hmm maybe this can help?

https://github.com/networknt/openapi-bundler

oh it is written with java

needim avatar Sep 28 '22 13:09 needim

hmm, https://redocly.com/docs/cli/commands/bundle/

needim avatar Sep 28 '22 13:09 needim

So, if I understood correctly you have one main spec and that spec points to different sub specs with ref path, right?

needim avatar Sep 28 '22 13:09 needim

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

cezarneaga avatar Sep 28 '22 13:09 cezarneaga

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

cezarneaga avatar Sep 28 '22 13:09 cezarneaga

for now, looks like you can bundle it by redocly cli

redocly.com/docs/cli/commands/bundle

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.

needim avatar Sep 28 '22 14:09 needim

+1 for redocly, we are using the exact same tool in my company to bundle our openapi specs 😁

fabien0102 avatar Sep 28 '22 14:09 fabien0102

i get Can't resolve $ref errors from redocly 🤷🏻‍♂️

cezarneaga avatar Sep 28 '22 14:09 cezarneaga

Can you share the trimmed versions of the 2 specs? So I can test.

needim avatar Sep 28 '22 14:09 needim

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

cezarneaga avatar Sep 29 '22 09:09 cezarneaga