Write TypeSpec, emit OpenAPI
Emitting OpenAPI from TypeSpec enables seamless cross-language interaction, automates API-related tasks, and simplifies API management and evolution.
Get started
import "@typespec/http";
using Http;
model Pet {
name: string;
age: int32;
}
model Store {
name: string;
address: Address;
}
model Address {
street: string;
city: string;
}
@route("/pets")
interface Pets {
list(@query filter: string): Pet[];
create(@body pet: Pet): Pet;
read(@path id: string): Pet;
}
@route("/stores")
interface Stores {
list(@query filter: string): Store[];
read(@path id: string): Store;
}
Ecosystem
Interoperate with the OpenAPI ecosystem
Benefit from a huge ecosystem of OpenAPI tools for configuring API gateways, generating code, and validating your data.
Linters
Integrate with spectral to lint your OpenAPI.
→
Ecosystem
Abstract recurring patterns
Transform API patterns into reusable elements to enhance both the quality and uniformity of your API interface.
Example: TypeSpec Azure Library
The TypeSpec library for Azure allows multiple teams to reuse pre-approved patterns.
→
import "@typespec/http";
using Http;
// Define abstraction for resource lifecyle
op ResourceList<T>(@query filter: string): T[];
op ResourceRead<T>(@path id: string): T;
@post op ResourceCreate<T>(...T): T;
model Pet {
name: string;
age: int32;
}
@route("/pets")
interface Pets {
list is ResourceList<Pet>;
create is ResourceCreate<Pet>;
read is ResourceRead<Pet>;
}