72 points · by FinTechFounder · 2y ago · 28 comments
We evaluated c# and typescript.
Which sucks, because the alternatives aren’t much better. Maybe I’m missing something but the swagger/openapi client generators shouldn’t be this bad as a rule…
I think the code might be the result of dealing with highly variadic endpoints (e.g accepts either JSON or XML, and accepts either basic auth or OAuth, and produces one of 4 different response objects), combined with trying to minimize the bundle size for browsers. The code looks extremely lean; I wouldn't be surprised if more explicit code was 10x the size.
That doesn't really explain the C# code; I'm not a C# dev, but I wouldn't expect "lines of code" to directly impact performance the way it does for browsers.
And yes! one reason why TypeScript is not yet "stable" when compared with other languages is because we've spent a great deal of time optimizing for size. One of the many optimizations was to use interfaces over classes whenever possible, and when not, use proxies over actual classes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
This is why for a small set of operations (<100) the added weight of a TypeScript client at runtime is almost negligeable.
For dotnet size matters as well, especially when you consider scenarios like embedded or front end development or large APIs. Similarly, we've spent time optimizing for runtime size.
We could have had so much better UX, there really is no reason to have it as bad...
I hand roll the http client libraries, too
For other languages, I suppose it's an organizational effort within MS to standardize and consolidate SDK generation to produce consistent experience.
More on .NET, last time I compared OpenAPI generator options - other generators did not do this or did it in a worse way.
Even still, I do not consider Kiota to have the kind of UX that .NET deserves.
For example, to consume gRPC-based API, your workflow is just:
dotnet add package Grpc.Tools
dotnet add package Grpc.Net.Client
dotnet add package Google.Protobuf
# add <Protobuf Include="myapi.proto" /> to .csproj
That's it - the client is generated transiently and is a part of the project without getting in your way, I have a small shell script to do it as a one-liner. And maintaining a dependency of an application on a remote API of this kind is also easy if .proto is available via git - add it as a submodule or a subtree and just bump commits automatically (or manually if review is needed).You never need to manually re-generate and possibly re-reference or re-publish a separate client package for this to work. The sheer convenience of this at both individual and organizational level alone makes a compelling case for choosing gRPC over REST, architectural preferences notwithstanding.
Last time I checked, Kiota required much more effort and ceremony. I understand that it's a "big generator to rule them all" that made to address both simple one-off APIs and ginormous Azure SDK, but .NET has all necessary building blocks to have similar or even better UX to what gRPC tooling provides. I suppose, it's just a matter of doing it and promoting the project.
The only set of public SDKs generated by kiota from Microsoft are the Microsoft Graph SDKs.
So I wrote a small utility to generate typescript types based on openapi files, so that they can be applied to an axios client.
No code, just types. Quite out of date now though.
https://github.com/ivank/laminar/tree/main/packages/cli#axio...
It doesn't immediately look like kiota can be extended in the same way swagger-codegen-cli can with custom generators, which is a shame. Definitely a nice feature.