fermyon / hippo-openapi

OpenAPI clients and related artifacts for Hippo
Apache License 2.0
3 stars 3 forks source link

replace javascript client with a typescript client #4

Open bacongobbler opened 2 years ago

bacongobbler commented 2 years ago

typescript is a superset of javascript, so in theory we should only need to generate a typescript to support both.

itowlson commented 2 years ago

The tool has a bunch of TypeScript generators. The obvious one, typescript-node, is pretty ropey: it doesn't generate a readme, and several of the dependencies are really old (installing produces warnings about deprecation, vulnerabilities, and being out of support). typescript-axios builds cleanly but introduces a very public axios dependency (e.g. the APIs return AxiosResponse rather than any abstraction); I'd this also rules it out of use in the browser. typescript-fetch builds cleanly, has unobstructed types, and has no dependencies. The other ones seems to be aimed at specific environments (Rx, Angular, Aurelia).

My suggestion is that we add typescript-fetch as a generator. It would be good to retire the native JS generator to avoid confusion, but I'm not sure of the compatibility implications or where the JS one is currently used. If it's used in the Hippo app, we could keep it around for around so that work in progress isn't blocked on a migration (or by any issues using the TS one in a browser), then retire it once the migration is complete.

itowlson commented 2 years ago

Well, that turned out to be a bad plan. Although typescript-fetch looked great on paper, it looks like it's only supported in recent (and non-LTS) versions of Node. There's a fetch polyfill, but drum roll the latest version is ES Modules only, which means it doesn't work in Electron.

What a shambles.

itowlson commented 2 years ago

The old version of the fetch polyfill doesn't work either.

bacongobbler commented 2 years ago

What does HashiCorp/nomad-openapi use? IIRC they have a typescript client available for use.

itowlson commented 2 years ago

Hmm, they found one just called typescript:

generatorName: typescript

Let me go look at the tool again and see if I've missed something.

itowlson commented 2 years ago

Well, yay. It's not mentioned in the list, but it does exist.

image

HOIST THE LIGHTNING CONDUCTOR IGOR

itowlson commented 2 years ago

Appears to depend on fetch, and the polyfill it uses is documented as not working in Node (I got a XMLHttpRequest error).

I tried to install the Nomad one to see what they were doing and it wouldn't even compile...!

itowlson commented 2 years ago

Okay I switched to Axios because it was the only one I could find that seemed to work with Node. Longer term, fetch will be portable across browser and Node but we're not there yet. Until then we may have to offer separate browser and Node libraries which seems ridiculous...

radu-matei commented 2 years ago

I used cross-fetch in the past for this specific purpose (but haven't lately..)