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
Kobayashi Kazuhiro
August 28, 2024
Programming
1.3k
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
82
Other Decks in Programming
See All in Programming
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
220
Oxlintはいいぞ(続)
yug1224
1
520
自分的「カンファレンスの楽しみ方」
syumai
0
170
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
340
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.4k
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
740
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
260
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
690
VibeCodingからAgenticWorkflowへ
starfish719
0
1.1k
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
ソフトウェアラスタライザ
fadis
1
760
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
270
Featured
See All Featured
Navigating Team Friction
lara
192
16k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
430
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
64k
Ruling the World: When Life Gets Gamed
codingconduct
0
320
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
430
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
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" }
👏 ご清聴ありがとうございました 👏