Show HN: An opinionated and statically-typed TypeScript SDK generator (easysdk.xyz)
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.
46 comments
[ 2.8 ms ] story [ 112 ms ] threadI 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.
[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...
It looks like all the data interfaces add this, which will (a) happily swallow typos, and (b) give you no warning that you might be pushing extra (i.e. private) data to the remote.
I understand that some people like the flexibility it provides, but it would be nice for that to be an option. There's no way I'd use the generated types with that, and the tool has a lot less value if I still have to go in and modify its output by hand.
It comes because we’re a bit pragmatic: if a user doesn’t specify their full data structure in their OpenAPI specification, and we can’t generate a strict type, we allow an arbitrary structure to reach the backend. In our experience the hard bit isn’t really writing the SDK, it’s making and maintaining a good OpenAPI spec (hence part of the commercial product we’re moving towards is the ability to generate a strict OpenAPI specification directly from handler code / traffic analysis in a backend server). Your concern is totally valid, and this is something we will make configurable.
Will send you a private message when it's ready.
Looking at the TIOBE index, the market for C# language products is more than 5x bigger than the market for golang products.
Golang might be more popular here on hacker news, but if you're running a business, C# is a disproportionately important language compared to what you'd think if you only read posts on HN.
https://github.com/RicoSuter/NSwag
Works a treat and is open-source, integrates nicely with ASP WebAPI projects. Can even generate TypeScript clients with a choice of HTTP library (axios/fetch etc.) or even an Angular based client.
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:
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 questionsFor anyone looking for more (open-source) alternatives, here's one I just discovered today: https://microsoft.github.io/kiota/
https://github.com/RicoSuter/NSwag
We use the C# client generator in our public sector project and package the results up within Nuget, works a treat.
But I like your idea of the universal generator. NSwag isn't the most friendly of things to configure & regenerate so something like your lovely site will make it easier for people. Best of luck with the project!
Have you guys written this entirely from scratch or done your own mustache templating on top of openapi-generator?
Would you mind to share, how the animation was made? I would imagine sth. like blender + after effects + lottie..
Let me know if you have more questions.
For anybody that still uses Java. :D
https://github.com/BlueCircleSoftware/bluecircle-json-interf...
On my screen, the website is scrollable. Not sure if the animation needs to have top: 30vh and height: 80%
Also: there is a big layout shift right after loading.
This easily shaves hours off a production quality api integration.