本文へ移動

oasis-genOpenAPI 3.2 向けの最小限の API クライアント生成ツール

出力は依存関係のない TypeScript ファイル 1 つで、すべての操作の型と fetch ベースの小さなランタイムを含みます。

例 ​

sh
npx oasis-gen openapi.yaml -o src/api.ts
ts
import { 
createClient
} from "./api.ts";
const
api
=
createClient
({
baseUrl
: "https://api.example.com" });
const
res
= await
api
.
GET
("/pets/{petId}", {
path
: {
petId
: 1 } });
if (
res
.
status
=== 200) {
res
.
data
.
name
; // 200 のレスポンスから型付けされる
} else if (
res
.
status
=== 404) {
res
.
data
.
title
; // 404 のレスポンスから型付けされる
}