![]() |
|
OpenAPI's 'type system' is surprisingly advanced also, supporting explicitly discriminated unions and other things like that, which doesn't model well into all other languages.
|
![]() |
|
Yep and that comes from JSON Schema: https://json-schema.org/ I believe recent versions of OpenAPI are "compatible" with JSON Schema (at least they "wanted to be" last I checked as I was implementing some schema converters). Even TypeScript is not enough to represent all of JSON Schema! But it gets close (perhaps if you remove validation rules and stuff like that it's a full match). But even something like Java can represent most of it pretty well, specially since sealed interfaces were added. I know because I've done it :). |
![]() |
|
It must be a new policy, or maybe only for this product (which makes good marketing). I've used Microsoft Graph to manage emails, and I'd be very surprised if they use if for Outlook... |
![]() |
|
I failed to find an answer to the main question: what output languages are supported. The only way is to emit OpenAPI and then using one of their terrible generators?
|
![]() |
|
You can create your own emitters, there's info in the docs on how to do so. My team built a custom TypeSpec emitter to output a SDK and set of libraries
|
![]() |
|
I still use WSDLs, or rather the platform I work on does. Maybe not popular for new tech but they are still alive. Hate me, but I’d rather have generated xml than generate yaml.
|
![]() |
|
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. |
![]() |
|
I added support for typespec as an input specification to my openapi 3 based code generator a couple of days ago. They provide an API to convert to openapi documents so it was pretty painless (https://github.com/mnahkies/openapi-code-generator/pull/158) My focus is on doing both client sdk and server stub generation, though only typescript so far - will hopefully add other languages eventually, when I'm satisfied with the completeness of the typescript templates. |
![]() |
|
CORBA, Avro RPC, Thrift RPC, gRPC, now this. In this industry each generation wants to re-invent IDL every decade. But anything is better then JSON over HTTP so why not this.
|
![]() |
|
Not quite. pkl is a language that is mostly designed for parsing and serialization of data. TypeSpec is a language that is designed to describe APIs and the structure of data that those APIs take. You can actually combine the two technologies as follows: 1. Read a .pkl file from disk and generate (for example) a Person struct with a first, last name and an age value. 2. Let's say that according to some TypeSpec, the HTTP endpoint /greet accepts a POST request with a JSON payload containing a first and a last name. You convert your Person struct into a JSON literal (and drop the age field in the process) and send it to the HTTP endpoint 3. You should receive a greeting from the HTTP endpoint as a response. The TypeSpec may define a greeting as a structure that contains the fields "message" and "language". 4. You can then use pkl to write that greeting structure to disk. Sidenote: pkl also supports methods[1] but in almost all use cases you only use pkl to define which fields your data has. TypeSpec cares most about the methods/endpoints. Of course, you still need to define the shape of the arguments to these methods and that is where you have a bit of overlap between these two technologies. I can imagine that you would generate pkl definitons from TypeSpec definitions. [1] https://pkl-lang.org/main/current/language-reference/index.h... |
![]() |
|
Yeah, but this one is better because new. I might be wrong, but I suspect that the crazy hype-driven-development has started to move on from frontend to backend. |
![]() |
|
Bespoke languages are a hard sell and incur significant extra effort on the team building this. 1. People don't want to learn bespoke languages. 2. You have to build all the ecosystem tools for a language (compiler, docs, language-server, IDE integrations, dependency management) Similar endeavors are WaspLang and DarkLang, which I have yet to see in the wild or (meaningfully) on HN. Better to use an existing language and focus on the value add. I personally built something with similar value add (source of truth -> all the things). I've been through some of these pain points myself. https://github.com/hofstadter-io/hof The idea is CUE + text/template = |
![]() |
|
There are some AI companies focusing on chatbots for developer projects that do better than using a general purpose LLM. I think this will become more common and not really a barrier |
![]() |
|
CUE is building out language bindings for various languages right now Since CUE is written in Go, you can output a .so that is then used like your C based desire, if I understand you correctly |
![]() |
|
Has validations thats awesome. I have a project in mind and was looking for something like this. Closest I found was CueLang. Now just need to find the time... |
![]() |
|
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-server implementation (see: https://www.npmjs.com/package/json-server). |
![]() |
|
Hmm. So as I understand it, it generates handler definitions which you then implement for typesafety but routing/hooking up is an implementation detail?
|
![]() |
|
I am still trialing Smithy, but as far as I understand, the code which is generated by Smithy, generates suitable abstractions and you never modify this code yourself. It leaves the middleware library selection for the user, and with middleware you can do whatever more complex operations you need. TypeScript server overview: https://smithy.io/2.0/ts-ssdk/introduction.html > This execution flow allows the service developer to choose not only their endpoint, but the programming model of their service. For instance, all of the shim conversion and handler invocation can be refactored into a convenience method, or the service developer could choose to incorporate their favorite open source middleware library, of which the server SDK would simply be one layer. It also allows open-ended request preprocessing and response postprocessing to happen independent of Smithy. For instance, a developer could add support for request or response compression, or a custom authentication and authorization framework could be plugged into the application before the server SDK is invoked, without having to fight against a more heavyweight abstraction. The Service type itself also seems to make it possible to define quite complex logic: https://smithy.io/2.0/spec/service-types.html |
![]() |
|
Smithy is _very_ similar to Coral (an internal library within Amazon). Coral is used by every AWS service -- every AWS service defines their APIs using Coral, and if you want to interact with another service you use a generated client. The client can generally be used as-is, though sometimes you might want some custom client code. In the case of a generated client you can just grab the API definition of the API you want to call, generate the client in the language of your choice, and... that's it! For the server, you still have to implement the logic of how to form the responses, but what the request/responses look like it enforced by the framework. Here's an example: https://gist.github.com/shepherdjerred/cb041ccc2b8864276e9b1... I'm leaving out a _lot_ of details. Coral is incredibly powerful and can do a lot of things for you for free. Smithy is, from what I can see, the same idea. |
![]() |
|
What if you need to generate two server implementations (possibly in different languages) that adhere to the same specification? You don’t always go server -> spec -> client. |
![]() |
|
the whole point of a DSL for APIs is so it can interop with different languages, frameworks and toolchains. Sure if you all your services are NestJS then you don't need this.
|
![]() |
|
If you are in a situation where you have a backend and you want to expose an API and then you would eventually want a client, you would need format specs as the starting point where server and clients are generated from that one source. At the moment, OpenAPI with YAML is the only way to go but you can't easily split the spec into separate files as you would do any program with packages, modules and what not. There are third party tools[0] which are archived and the libraries they depend upon are up for adoption. In that space, either you can use something like cue language 1] or something like TypeSpec which is purpose built for this so yet, this seems like a great tool although I have not tried it yet myself. [0]. https://github.com/APIDevTools/swagger-cli [1]. https://cuelang.org/ EDIT: formating |
![]() |
|
Why create a new language, rather than use an established programming language like Go where you can actually write an implementation too?
|
![]() |
|
I would have expected a bit more than type specifications, maybe some behavior specifications also? Something like Daan’s type states. But I get why we are still splitting hairs over data types.
|
![]() |
|
I've been working on an API spec language where state changes can be modeled with linear logic: https://apilog.net/docs/why/ It doesn't have "schemas" yet though. Which may seem odd given they are a crucial part of this type of languages. :-) But it is because I am experimenting with different designs on that front.
|