Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
Transcript
11 slides
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" }
👏 ご清聴ありがとうございました 👏
More Decks by Kobayashi Kazuhiro
See All by Kobayashi Kazuhiro
Vue 2 の EOL まで 2 ヶ月ですが進捗どうですか?
kzhrk
1
13k
メドピアのサービスにおけるテスト戦略の過去と未来 〜かかりつけ化薬局⽀援サービス kakari 〜
kzhrk
0
88
Other Decks in Programming
See All in Programming
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
260
SODA - FACT BOOK(EN)
sodainc
1
230
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
180
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
230
LLM 101
dalinaum
0
480
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.7k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
380
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
310
GraphQL の onError と Nullability のこれから
quramy
0
210
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
5.6k
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
260
Featured
See All Featured
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
460
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
Optimizing for Happiness
mojombo
378
71k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
470
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Claude Code のすすめ
schroneko
67
230k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Un-Boring Meetings
codingconduct
0
490
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k