cloud-sdk-js
cloud-sdk-js copied to clipboard
Support generating ESM OpenAPI clients
Is your feature request related to a problem? Please describe.
We want to setup a new Typescript Node project using the newer ESM syntax. We also want to generate an OpenAPI client using the Cloud SDK that then shall be used in the Node project. The generated client however uses relative imports without file extensions like so
// ./generated-client/index.ts
export * from "./some-file";
When using the ESM syntax it is required to specify the file extension for relative imports. So when the client is (re-)generated it currently is required to manually add the .js file extension to all relative import statements.
Describe the solution you'd like
It would be nice to e.g. a flag for the generator to choose between ESM and CommonJS (import) syntax. Or generally any way to make the generated code work with an ESM based project without having to make manual changes.
Describe alternatives you've considered
- Switching the whole project to use CommonJS
- Manually adding the missing file extensions
Impact / Priority
Additional context
Hey @sven-petersen, thank you for the suggestion, we will discuss it. The ESM topic is generally on our radar as well 😊
We have discussed this and took it into our backlog. This will require a bit of investigation to understand whether just switching the endings for the imports is enough. Also, we would have to add a few more tests for ESM. Generally, I think your proposal to do this with a flag makes a lot of sense, so thank you for that. From the viewpoint of the SDK this would be a feature that is interesting for both the OpenAPI and the OData generator.
Still, for now, I cannot give you a timeline, when this might be worked on.
Could you please implement the ESM syntax for the OData generator as well.
Hey @sven-petersen, we've just added support for ESM to our OpenAPI generator, feel free to let us know if everything works as intended for you.
@yurecz, I have added your feature request to our backlog, given our current capacity, this will most likely take a while.
Hey @sven-petersen, we've just added support for ESM to our OpenAPI generator, feel free to let us know if everything works as intended for you.
Tested it, and looks good. Thanks! You can close this issue if you want - or keep it open in case you want to use this as a reminder for @yurecz feature request.
@yurecz, I will close this issue as the OpenAPI generator is working as expected. We won't forget to add ESM support for our Odata generator, as we always strive to align our generators. However, as I mentioned, this will most likely take a few more weeks.