Live data from Hacker News

Show HN: An opinionated and statically-typed TypeScript SDK generator

easysdk.xyz

1–10 of 47 posts

Show HN: An opinionated and statically-typed TypeScript SDK generator

#1
Hi Hacker News!

My name is Sagar, I’m working on a startup called Speakeasy - we’re making all APIs self-service. The platform is currently in beta, but we’re independently launching this tool which you can use to generate language-idiomatic, statically-typed TS SDKs from any public OpenAPI schemas. We hope to continue iterating on this to give devs a way to easily generate high fidelity client SDKs for all the major languages.

Inspiration for this product is from past experiences struggling with OpenAPI. I was originally optimistic about using the OpenAPI tools to build out our offering, but quickly realized that the tools left a lot to be desired, and would not have provided our end users with the developer experience we wanted. While it’s not exhaustive, we’ve tried to address some of the biggest gaps in this tool:

* Low-dependency - To try and keep the SDK isomorphic (i.e. available both for Browsers and Node.JS servers), we wrap axios, but that’s it.This is intended to be idiomatic typescript; very similar to code a human would write; with the caveat that the typing is only as strict as the OpenAPI specification.

* Code just like a human would write - At this point static typing is everywhere. So wherever possible, we generate typed structures, construct path variables automatically, pass through query parameters, and expose strictly typed input / output body types.

* Future direction - There’s value in being neutral, but we felt like there is more value in being opinionated. In the future we’ll add features like built-in Pagination, Retries (Backoff/Jitter etc), Auth integrations, which should be handled in the SDK.

We’re planning to continue improving this service, so would love to hear what you think of the choices we’ve made, the issues we should address next, and what languages we should work on supporting.

Show HN: An opinionated and statically-typed TypeScript SDK generator
easysdk.xyz

Re: Show HN: An opinionated and statically-typed TypeScript SDK generator

#4
post #2

Congrats on the launch! I think it might be interesting to provide some examples without the need to upload a schema, since I assume most people playing with it won't have one ready right off the bat.

You can go to the Swagger Editor [1], download the default Pet Store schema as a JSON file, and upload it here to see an example in action.

[1]: https://editor.swagger.io/

Edit: Apparently their URLs are public, so here is the Pet Store schema I uploaded https://easysdk.xyz/sdk/openapi.json-a09be341882b7aa7b87eb40...

Re: Show HN: An opinionated and statically-typed TypeScript SDK generator

#9
Hey all ! I worked on this with Sagar a couple weeks back. The tl;dr of this is that it generates a (in my heavily-biased opinion) relatively clean SDK given an OpenAPI schema, similar to what a human would write. We’d used several other OpenAPI SDK generators but found their result to be a bit too big (and not tree-shakable); so spent a bit of effort trying to work out a way to compile-in the OpenAPI spec into a thin (but statically typed) wrapping around axios — very similar to an SDK coded manually.

Here's a few examples:

1. The Petstore API (an tiny example): https://easysdk.xyz/sdk/petstore.json-7bb7c53e017c0f7432f7bd...

2. Our own API: https://easysdk.xyz/sdk/openapi.yaml-ee89154ee9cf9a77f9fb07d...

3. The LOTR API: http://easysdk.xyz/sdk/lotr.yaml-f1ec4cde1ca7839dca2685e283e...

The generator works by:

1. Dereferencing an OpenAPI specification into something with inline types. (Ideally we'd handle type references rather than inlining them, but haven't got there yet)

2. Walking the type-graph, and mapping it to Operations (a combination of Path and Method).

3. Using the Typescript SDK, generating the SDK via creating AST nodes whilst walking the type graph.

4. Trying to compile in:

    1. Path Parameters as ES6 Template strings (e.g. `"/v1/apis/{apiID}/api_endpoints"` => `/v1/apis/${props.apiID}/api_endpoints`)

    2. Query params into axios parameters

    3. Body params as an additional argument to the SDK
It's not perfect, but we've used this to help run our own unit tests (and have a few customers trying it out too)! Happy to answer any questions
Post reply on HN