TypeSpec language preview
1. A user model and route
decorators, a model, and an HTTP interface
horizon-dark
import "@typespec/http";
using TypeSpec.Http;
@doc("A simple user model")
model User {
@key
id: string;
name: string;
age?: int32;
}
@route("/users")
interface Users {
@get op list(): User[];
}
atom-one-dark
import "@typespec/http";
using TypeSpec.Http;
@doc("A simple user model")
model User {
@key
id: string;
name: string;
age?: int32;
}
@route("/users")
interface Users {
@get op list(): User[];
}
github-dark
import "@typespec/http";
using TypeSpec.Http;
@doc("A simple user model")
model User {
@key
id: string;
name: string;
age?: int32;
}
@route("/users")
interface Users {
@get op list(): User[];
}
dracula
import "@typespec/http";
using TypeSpec.Http;
@doc("A simple user model")
model User {
@key
id: string;
name: string;
age?: int32;
}
@route("/users")
interface Users {
@get op list(): User[];
}
nord
import "@typespec/http";
using TypeSpec.Http;
@doc("A simple user model")
model User {
@key
id: string;
name: string;
age?: int32;
}
@route("/users")
interface Users {
@get op list(): User[];
}
github
import "@typespec/http";
using TypeSpec.Http;
@doc("A simple user model")
model User {
@key
id: string;
name: string;
age?: int32;
}
@route("/users")
interface Users {
@get op list(): User[];
}
2. Validation decorators
minLength, maxLength, and pattern
horizon-dark
model Username {
@minLength(3)
@maxLength(20)
@pattern("^[a-z0-9_]+$")
value: string;
} atom-one-dark
model Username {
@minLength(3)
@maxLength(20)
@pattern("^[a-z0-9_]+$")
value: string;
} github-dark
model Username {
@minLength(3)
@maxLength(20)
@pattern("^[a-z0-9_]+$")
value: string;
} dracula
model Username {
@minLength(3)
@maxLength(20)
@pattern("^[a-z0-9_]+$")
value: string;
} nord
model Username {
@minLength(3)
@maxLength(20)
@pattern("^[a-z0-9_]+$")
value: string;
} github
model Username {
@minLength(3)
@maxLength(20)
@pattern("^[a-z0-9_]+$")
value: string;
} 3. Enums and unions
an enum and a union of string literals
horizon-dark
enum Status {
Active,
Inactive,
}
union Role {
"admin",
"member",
} atom-one-dark
enum Status {
Active,
Inactive,
}
union Role {
"admin",
"member",
} github-dark
enum Status {
Active,
Inactive,
}
union Role {
"admin",
"member",
} dracula
enum Status {
Active,
Inactive,
}
union Role {
"admin",
"member",
} nord
enum Status {
Active,
Inactive,
}
union Role {
"admin",
"member",
} github
enum Status {
Active,
Inactive,
}
union Role {
"admin",
"member",
}