client-nodejs icon indicating copy to clipboard operation
client-nodejs copied to clipboard

Generate TypeScript types and interfaces

Open bvobart opened this issue 3 years ago • 39 comments

Hi Pipedrive team! As I understand, this Pipedrive client library has been generated based on the OpenAPI specification since v11. Is it possible for the client generator to also generate TypeScript types / interfaces for the client?

That would make it much easier to use this library in a type-safe way in TypeScript projects. Even in plain JavaScript projects, the IDE would feature better support and recommendations for working with this library. I'm not sure what generator you're using, but this seems like a relatively low effort high reward solution.

bvobart avatar May 13 '22 11:05 bvobart

I see you are using https://github.com/openapitools/openapi-generator, which according to their ReadMe has support for generating TypeScript NodeJS clients :)

bvobart avatar May 13 '22 14:05 bvobart

I experimented with running openapi-generator-cli generate -i https://developers.pipedrive.com/docs/api/v1/openapi.yaml --generator-name typescript-node -o . to see if I could generate a TypeScript version of this Pipedrive client myself, but I'm getting a whole bunch of [main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: object warnings, and some unresolvable base types.

I don't know how you generate the code in this repository, as you have not open-sourced the generator code as far as I could find, so I can't help you (or myself) there very much.

But the idea is pretty simple:

  • Configure openapi-generator to use one of their TypeScript targets, whichever fits you best.
  • Create a tsconfig.json file (tip: check @tsconfig packages for a stable base)
  • Add tsc to your package.json's build command.
  • Reconsider the Babel configuration, some of the things Babel does might not be necessary anymore as TypeScript can do them too.

bvobart avatar May 16 '22 11:05 bvobart

Hey @bvobart! Thanks for sharing the relevant details. Highly appreciate that :)

Tagging our SDK expert @RuTsEST to bring more visibility.

hemchander23 avatar May 24 '22 08:05 hemchander23

Hi guys! TypeScript is in the plans, but not for the near future. Proper testing needs to be done and it will certainly need some adjustments before a release. Stay tuned!

SpaceOven avatar May 24 '22 10:05 SpaceOven

@SpaceOven @RuTsEST Thanks for your answer! I understand that it is difficult to pin down a particular date, but can you give a more concrete indication as to when "in the plans, but not for the near future" will be?

Also, this issue is not yet resolved as no TypeScript support has been implemented yet, so may I ask why you closed this issue? It'd be very useful for all of us waiting for TypeScript support to see this issue in the open issues list and be kept up to date here about the progress (or lack of progress) on this issue.

As a final note (perhaps a bit off-topic): in this repo you have open-sourced the NodeJS Pipedrive API client implementation, but since this is a generated client, pull requests to this repo from contributors are practically useless. I've seen a few PRs being shot down with a comment like 'thanks for the contribution, but we have to update it in our generator code' That generator code, however, is not open-sourced afaik, so there is no way for contributors to aid in fixing small bugs or experimenting with proper TypeScript support. What are your thoughts on this? And have you considered open-sourcing the generator code?

bvobart avatar Jun 13 '22 10:06 bvobart

I think this issue should be kept open

typescript is the minimal to provide a good dx

sibelius avatar Jun 20 '22 17:06 sibelius

Hey @bvobart, @sibelius!

Thanks for your interest in the SDK! Unfortunately I'm not in position to say when we're going to implement the typescript version of the SDK. Maybe @HappyVlad can give more concrete estimates?

The project itself could be quite big as well with quite a few unknowns:

  • making the underlying YAML files compatible with the TS generator (there are hundreds of them and this is probably the biggest time sink)
  • making sure it has dual auth support (OAuth and api-token) and implementing it if needed
  • supporting multiple instances for different users and different apps https://github.com/pipedrive/client-nodejs/issues/318.

Maybe releasing the alpha/beta version of the typescript SDK with the underlying generator would be the best course of action since we could start working on it iteratively?

I do also agree that in order to let 3rd party developers contribute more efficiently to our SDKs, the underlying generators could be made open source but the security guys might require prior work to make it publishable. Also it's not that difficult to copy over the JS changes to the templates so PRs with JS changes and improvements are still useful for us though I agree it's not perfect.

RuTsEST avatar Jul 12 '22 08:07 RuTsEST

bump .. this is 2022 n this is a paid product

JeremySazMining avatar Aug 10 '22 22:08 JeremySazMining

⚠️ this doesn't support (at least) different response status codes, but in case it's helpful to someone:

I generated types with https://developers.pipedrive.com/docs/api/v1/openapi.yaml

npx openapi-typescript openapi.yaml --output pipedrive.ts

.. then I deleted exports from that file and made it a .d.ts, and added a declaration at the top (I'm just using ApiClient + DealsApi.getDeals but should be obvious how to add other methods)

pipedrive.d.ts: https://gist.github.com/markstreich/656c17e737d504f2c530faab697342d4

which gives me what I wanted (some helpful vscode typehints):

Screen Shot 2022-11-05 at 8 40 13

markstreich avatar Nov 05 '22 06:11 markstreich

Hey @RuTsEST & @HappyVlad

Is it possible to start a branch for the TypeScript conversion in this repo and have it overlooked by the PipeDrive team?

I noticed you mentioned "The underlying generators could be made open source but the security guys might require prior work to make it publishable" so how long would you estimate that something like this would take?

WMRamadan avatar Dec 01 '22 08:12 WMRamadan