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
161 stars 51 forks source link

Provide a way to hook into the Services generation proces #4715

Open uroslates opened 1 month ago

uroslates commented 1 month ago

Is your feature request related to a problem? Please describe. When the generation process is triggered there might be a need to, in addition to the ts types & apis (services) generation, also provide an async 'hook' function which would allow the sdk consumers to register their own code doing any extra generation specifically related to the public api layer. As an example our team's requirement is exposing the api's as public procedures. Implementing this through this kind of hooks (if provided) would eliminate lots of potential problems we might have if not using this approach (like performance optimisation or more importantly maintainance issues we could have if using parsers different than the one used internally by the sap cloud sdk.

Describe the solution you'd like When using the sap cloud js sdk (programatically only) it would be great to provide a js hook configuration option where the consumers could provide a custom function, that would be triggered during each api/service generation iteration, where they could register thier custom (generation) code enabling them to reuse sap cloud sdk js parsed schema. Here is an possible example:

await generate({
    input: '/path/to/openapi/schemas/open-api-schema.json',
    outputDir: '/path/to/output/',
    skipValidation: true,
    generationHook: async function (
      serviceDirPath: string,
      serviceName: string,
      apiServiceName: string,
      api: any,
      options: CreateFileOptions
    ) {
      await RpcProcedureBuilder.generateProcedure(
        '/path/to/generated/procedures/folder/',
        serviceName,
        apiServiceName,
        api,
        options
      );
    },
    clearOutputDir: true
  });

Describe alternatives you've considered Use custom solution not relying to cloud sdk parsing & generation which as described above has its negative implications.

marikaner commented 1 month ago

Hey @uroslates, thank you for your contribution. We need to check how and if we can integrate your proposal and whether your approach fits our API. This will take us some time, but we will let you know as soon as we can.