SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
162 stars 55 forks source link

Generate Client for Specific Entities with in an EDMX #4931

Open nsathya2010 opened 3 weeks ago

nsathya2010 commented 3 weeks ago

Is your feature request related to a problem? Please describe.

I’m always cumbersome to handle too many files when I need to generate OData clients for services with multiple entities, but I only require a client for a specific entity The current generator does not support generating clients for individual entities, leading to unnecessary code and increased complexity.

Describe the solution you’d like

I would like the SAP Cloud SDK OData client generator to support an option to generate clients for specific entities only. This could be achieved by providing an --include-entity/--exclude-entity flag or similar, allowing users to specify the entities they need.

Describe alternatives you’ve considered

I have considered manually editing the generated code to remove unwanted entities, but this is time-consuming and error-prone. Another alternative is to use the include option to specify files, but this does not address the need to filter entities within a single service specification.

Impact / Priority Affected development phase: Development, increased deployment size

Impact: Inconvenience

Additional context: This feature would greatly streamline the development process by reducing the amount of unnecessary code and simplifying the client generation process. It would also help in maintaining cleaner and more manageable codebases.

deekshas8 commented 3 weeks ago

Hi @nsathya2010 ,

Thank you for raising this. This would indeed be a nice feature in both the generators. I have created a backlog item for this. But given our current low capacity, I'm not sure whether we will work on this feature request anytime soon or not.

nsathya2010 commented 3 weeks ago

Hi @deekshas8,

Thanks for the acknowledgement.

Do you know any workaround for this. We are deploying 450 + files including transpiled JS. However, we only need 15 files max.

nsathya2010 commented 3 weeks ago

Hi @deekshas8 ,

I have a fork and I added few lines of code to filter the entities, could you please take a look if it is any good. I had added only of the OData Generator for now.

Fork

Thanks, Sathya

deekshas8 commented 3 weeks ago

Hi @nsathya2010 ,

Did you try this out for your service? Is it working the way you expect?

I briefly looked at the fork, and while having a list of string for entities to ignore would be the way to go, I see some potential issues.

  1. The names that the user sets in this list might not match the generated code since we do additional formatting for names in getServiceEntitiesV2 .
  2. The naming of the option selectedEntities in the common generator options since this does not entirely go with the OpenApi generator. I would like to give this a bit more thought.
  3. The new feature also needs more test coverage for all cases.

You can use the changes the at you have made if it's working for your use-case and create a PR contribution if you'd like to work on this further. But as mentioned before, we are a bit low on capacity and I would like to do this after more careful consideration on all edge cases.

Regarding maybe reducing the number of transpiled files, you can skip generation of declaration and source map files (if you don't need them) by passing your own tsconfig. The SDK by default generates them.

nsathya2010 commented 3 weeks ago

Hi @deekshas8 ,

It did work for me and the generated/transpiled files are now in production as it reduced 250+files. However, my service was OData V4. I made it work my copying the /dist and generated the files programmatically (not via CLI).

Thanks for the feedback. I will go through the v2 API name mapping and think about reversing the parameter selectedEntities to ignoreEntities. Only problem is too many entities to be given in case of ignore.

I will try and make more tests and raise a PR if it is ready.

Thanks, Sathya