Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
OpenAPI と型 | Mita.ts #1
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kobayashi Kazuhiro
August 28, 2024
Programming
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
OpenAPI と型 | Mita.ts #1
-
Mita.ts #1
-
GitHub
Kobayashi Kazuhiro
August 28, 2024
More Decks by Kobayashi Kazuhiro
See All by Kobayashi Kazuhiro
Vue 2 の EOL まで 2 ヶ月ですが進捗どうですか?
kzhrk
1
13k
メドピアのサービスにおけるテスト戦略の過去と未来 〜かかりつけ化薬局⽀援サービス kakari 〜
kzhrk
0
79
Other Decks in Programming
See All in Programming
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
270
継続モナドとリアクティブプログラミング
yukikurage
3
680
AIエージェントで 変わるAndroid開発環境
takahirom
2
770
React本体のコードリーディング
high_g_engineer
1
130
FDEが実現するAI駆動経営の現在地
gonta
2
260
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
390
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
470
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
530
Claude Team Plan導入・ガイド
tk3fftk
0
250
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
210
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
140
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
240
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
sira's awesome portfolio website redesign presentation
elsirapls
0
320
How to make the Groovebox
asonas
2
2.3k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
760
How to Think Like a Performance Engineer
csswizardry
28
2.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
First, design no harm
axbom
PRO
2
1.2k
Marketing to machines
jonoalderson
1
5.6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
360
Transcript
OpenAPI と型 Mita.ts#1 2024/08/28(Wed) 小林 和弘
OpenAPI とは HTTP API を記述するための標準仕様 API がどのように機能するか API がどのように連携するか テストを作成
クライアントコードを生成(型も生成) https://www.openapis.org/
Example https://github.com/kzhrk/mita.ts-1/blob/main/spec.yml openapi: "3.0.0" info: version: 1.0.0 title: Sample paths:
/items: get: summary: アイテム一蘭取得 operationId: getItems tags: - items parameters: - name: page in: query required: false schema: type: integer maximum: 100 format: int32 responses: '200':
型を生成する方法 OpenAPI generator OpenAPI TypeScript
OpenAPI generator Docker npm cf. Generators List https://openapi-generator.tech/docs/installation/ docker run
-t --rm \ -v ${CURDIR}:/local openapitools/openapi-generator-cli generate \ -i local/spec.yml \ -g typescript-axios \ -o local/sample/openapi-generator npx @openapitools/openapi-generator-cli generate \ -i ./spec.yml \ -g typescript-axios \ -o ./sample/openapi-generator
出力した型を読み込む OpenAPI で定義した operationId とステータスコードを元に抽象化された型が出力される。 import type { GetItems200ResponseInner }
from './sample/typescript-axios'; const item: GetItems200ResponseInner = { id: 1, name: '', }
OpenAPI TypeScript https://openapi-ts.dev/ npx openapi-typescript ./spec.yml -o ./sample/openapi-typescript/schema.d.ts
出力した型を読み込む OpenAPI のパスと operationId の巨大な interface が提供される。 import type {
paths, operations } from './sample/openapi-typescript/schema'; type Item = paths['/items/{itemId}']['get']['responses']['200']['content']['application/json']; type Item2 = operations['getItem']['responses']['200']['content']['application/json']; const item: Item = { id: 1, name: '', }; const item2: Item2 = { id: 1, name: '', };
まとめ OpenAPI generators generator から言語が選べる 抽象化した型を提供する OpenAPI TypeScript paths, operations
の巨大な interface を提供する openapi-fetch でテストのモックなども提供する
(時間が余ったら)自己紹介 { "name": "小林 和弘", "job": "Frontend Engineer@Medpeer", "x_twitter": "@kzhrk0430",
"github": "kzhrk" }
👏 ご清聴ありがとうございました 👏