-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to process multiple input files #2037
Comments
How would you handle conflicting service or model names? |
I'm new to this repo, so all I have is newb suggestions. Couldn't we just take in the service name as an argument either as CLI args or as a parameter in the programmatic API? I'm thinking something like: const OpenAPI = require('https://github.com/ferdikoomen/openapi-typescript-codegen');
OpenAPI.generate({
inputs: [
{ file: './spec1.ts', name: 'AuthService' },
{ file: './spec2.ts', name: 'PermissionsService' }
],
output: './generated',
}); Realistically though, it's unlikely for service names to clash in a project. If it does, it might even be ok to throw an error. I'm not sure about handling model names - when I ran codegen, my models folder was empty, so I don't have an opinion about it. But if the models are somehow scoped to the service, it shouldn't matter if their names clash with that of another service. |
Services are also generated from OpenAPI tags, so if the projects contain the same tag, there would be clashes. As for the empty models folder, did you run the generator with the For your original request, what do you think about a generated folder structure like this? src
└── client
├── core
├── project-one
│ ├── models
│ ├── schemas
│ ├── services
│ └── index.ts
├── project-two
│ ├── models
│ ├── schemas
│ ├── services
│ └── index.ts
└── index.ts Models, schemas, and services would be nested inside their project folders and exported through One question, do all your services work with the same authorization token? |
Yup, your suggestion looks good to me. You're right, my ask is that the I'm only newly getting onboarded to the project I'm working on, so I don't know too much about how the auth works. My current understanding is that it's the same token being used across services, but I could be wrong. Would that be something to handle as well when considering multiple spec inputs? |
Definitely – you'd need a mechanism to tell the shared core which token to use for which project. I think the easiest way for you is to build a separate client for each project. If your services can be connected seamlessly, you might get a better mileage out of modifying the generated files to do what you describe above (shared core, combined services, etc) |
Would it be possible to add support for multiple OpenAPI spec files? If such a support exists, could you please point me to how I can use it?
In my code, we need to talk to multiple services, and each have their own OpenAPI spec files, a copy of which we have in our repo. However, when I run
openapi-typescript-codegen
, since I can only give it one input file, the generated code is only oriented towards one service. However, it should be possible to reuse a lot of the stuff defined in thegenerated/core
directory, and we only need to create multiple service clients in thegenerated/services/
directory, and export them all in thegenerated/index.ts
file. Shipping multiple clients for each service is not ideal, since we're working on a front-end client, so need to minimise the code we ship to end users.I could maybe build a slightly ugly workaround, where I run
openapi-typescript-codegen
for each spec file, and then move some files and edit others, but it would be ideal if support for this was built in.The text was updated successfully, but these errors were encountered: