Saturday, November 23, 2024

TypeSpec vs OpenAPI

Very clever: Using TypeScript inspired language  for describing APIs. From Microsoft.

 typespec.io

Describe your data up front and generate schemas, API specifications, client / server code, docs, and more.

API-First for developers

With TypeSpec, remove the handwritten files that slow you down,
and generate standards-compliant API schemas in seconds.


import "@typespec/http";
using TypeSpec.Http;
model Store {
name: string;
address: Address;
}
model Address {
street: string;
city: string;
}
@route("/stores")
interface Stores {
list(@query filter: string): Store[];
read(@path id: Store): Store;
}

---

openapi: 3.0.0
info:
title: (title)
version: 0.0.0
tags: []