Live data from Hacker News

TypeSpec: A new language for API-centric development

typespec.io

81–90 of 121 posts

Re: TypeSpec: A new language for API-centric development

#81
post #23
post #10

What is wrong with protobufs and grpc?

Both of them. Both of them are wrong.

When one starts gluing together a lot of data pipelines full of JSON trash and from all kinds of systems with incompatible data types (whether or not “lol what’s an integer?” JSON is involved), one quickly comes to appreciate why things like Protobuf exist and look the way they do.

Re: TypeSpec: A new language for API-centric development

#82
This looks interesting but I already have TypeScript types for my APIs so I developed https://github.com/vega/ts-json-schema-generator which lets me generate JSON schema from the sources directly. Yes, it does have some oddities because the two languages have slightly different feature sets but it’s been working well for us for a few years. If I didn’t have TypeScript or a smaller API surface I’d be okay with typing again I would look at TypeSpec though. It definitely beats writing JSON schema by hand.

Re: TypeSpec: A new language for API-centric development

#83

Earlier quoted context omitted.

Exactly - this is already a solved problem. https://docs.nestjs.com/openapi/introduction

yes, the whole world runs on nestjs

https://github.com/domaindrivendev/Swashbuckle.AspNetCore

https://github.com/RicoSuter/NSwag

There is no need to be facetious, solutions like these exist for many platforms and ecosystems out there. I can't possibly entertain all of them.

By all means, if such similar solution does not exist for your platform, then TypeSpec could indeed be a solution for you.

With best regards.

Re: TypeSpec: A new language for API-centric development

#84

Spec api code, imo. Feels like it's going backwards - there's really no reason why it has to be a .tsp, instead of a .ts with actual api code. It's even using @annotations. In fact the annotations i see in the screenshot (@route, @query, @path) are practically the same in NestJS. I feel that we should be focusing on enhancing that paradigm instead. In fact I already have a working POC of NestJS -> OpenAPI -> Client l…

Basically my PoV. The API code itself is the best possible documentation. Not to mention, how else do you see what complex logic might happen in an endpoint? It seems typespec deals only with extremely simple CRUD APIs, for which again just reading the code would be good enough. In scenarios where you want to offer the API consuming team some mock, I'd argue time would be better spent providing them with a a json-ser…

If you can define single spec and autogenerate everything (client/server/OpenAPI et. al.), then spec first is superior.

Looking at https://smithy.io/2.0/index.html which can already generate much more than TypeSpec based on the docs and awesome list.

Re: TypeSpec: A new language for API-centric development

#85
post #59

Earlier quoted context omitted.

It’s probably more like smithy?

That’s what I thought when I saw this: smithy without the need to bring Gradle into your project

You don’t have to use Gradle with Smithy. You can also use the self-contained CLI which doesn’t use Gradle: https://smithy.io/2.0/guides/smithy-cli/index.html

Re: TypeSpec: A new language for API-centric development

#86
post #84

Earlier quoted context omitted.

Basically my PoV. The API code itself is the best possible documentation. Not to mention, how else do you see what complex logic might happen in an endpoint? It seems typespec deals only with extremely simple CRUD APIs, for which again just reading the code would be good enough. In scenarios where you want to offer the API consuming team some mock, I'd argue time would be better spent providing them with a a json-ser…

If you can define single spec and autogenerate everything (client/server/OpenAPI et. al.), then spec first is superior. Looking at https://smithy.io/2.0/index.html which can already generate much more than TypeSpec based on the docs and awesome list.

Hmm. So as I understand it, it generates handler definitions which you then implement for typesafety but routing/hooking up is an implementation detail?

Re: TypeSpec: A new language for API-centric development

#87

Earlier quoted context omitted.

+1. It even looks very similar to TypeScript. Why not use TypeScript as a description of APIs in the first place? Get TypeScript types and even generate OpenAPI schema on the fly to serve it at `/openapi`?

Exactly - this is already a solved problem. https://docs.nestjs.com/openapi/introduction

[deleted]

Re: TypeSpec: A new language for API-centric development

#88

Would be nice if you could just import those typespec files in typescript (and other languages?) and get automatic typescript types from them. Codegen is annoying and error prone.

+1. It even looks very similar to TypeScript. Why not use TypeScript as a description of APIs in the first place? Get TypeScript types and even generate OpenAPI schema on the fly to serve it at `/openapi`?

Typescript is too powerful, there are a lot of typescript constructs that can't be represented in OpenAPI specs. Or that could generate massively complex OpenAPI specs that would bring your tooling performance to a crawl.

A subset of typescript could work, but I imagine it would be fairly confusing to support some features here and other features there.

I think they are going for a minimum common denominator approach and eventually add other targets besides OpenAPI.

Re: TypeSpec: A new language for API-centric development

#89
post #84

Earlier quoted context omitted.

Basically my PoV. The API code itself is the best possible documentation. Not to mention, how else do you see what complex logic might happen in an endpoint? It seems typespec deals only with extremely simple CRUD APIs, for which again just reading the code would be good enough. In scenarios where you want to offer the API consuming team some mock, I'd argue time would be better spent providing them with a a json-ser…

If you can define single spec and autogenerate everything (client/server/OpenAPI et. al.), then spec first is superior. Looking at https://smithy.io/2.0/index.html which can already generate much more than TypeSpec based on the docs and awesome list.

I'm not sure how I can autogenerate non-trivial logic, which is my point.

How would you handle a typical case where based on request data an endpoint fetches some additional information from various sources and depending on that performs several different actions?

This is the most common scenario I've encountered outside of extremely trivial CRUD endpoints.

EDIT: don't get me wrong, I'm not being purposefully obtuse - I was a big swagger advocate back in the day, however over time I came to realize that effort was much better invested in writing clear API code and possibly a mock impl like json-server.

Re: TypeSpec: A new language for API-centric development

#90
post #43

Feels like cheating, next to the yaml of openapi anything will look good. And that's all while I'm still considering openapi one of the best things that have happened. But I've also been kind of holding my breath for typescript making it's breakthrough as a schema language. More specifically its surprisingly big non-imperative, non-functional subset, obviously. And at first glance this seems to be exactly this, "what…

> next to the yaml of openapi anything will look good.

Challenge accepted!

https://github.com/bufbuild/protovalidate/blob/main/examples...

Post reply on HN