Skip to content

Instantly share code, notes, and snippets.

@up1
Last active June 20, 2024 14:59
Show Gist options
  • Save up1/fab65907e5a7ffd46df068da7c2147bf to your computer and use it in GitHub Desktop.
Save up1/fab65907e5a7ffd46df068da7c2147bf to your computer and use it in GitHub Desktop.
TypeSpec 2024
// ติดตั้ง library
$npm install -g @typespec/compiler
// สร้าง project
$tsp init
TypeSpec compiler v0.57.0
? Please select a template › - Use arrow-keys. Return to submit.
❯ Empty project min compiler ver: 0.57.0 - Create an empty project.
Generic REST API min compiler ver: 0.57.0
TypeSpec Library (With TypeScript) min compiler ver: 0.57.0
TypeSpec Emitter (With TypeScript) min compiler ver: 0.57.0
$tsp install
// Compile typespec
$tsp compile .
import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";
using TypeSpec.Http;
model User {
firstname: string;
lastname: string;
age: int32;
}
@route("/users")
interface Users {
list(@query filter: string): User[];
create(@body user: User): User;
read(@path id: string): User;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment