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
More Decks by Kobayashi Kazuhiro
See All by Kobayashi Kazuhiro
Vue 2 の EOL まで 2 ヶ月ですが進捗どうですか?
kzhrk
1
13k
メドピアのサービスにおけるテスト戦略の過去と未来 〜かかりつけ化薬局⽀援サービス kakari 〜
kzhrk
0
84
Other Decks in Programming
See All in Programming
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
110
新卒PdEのリアル
ryu1013
1
470
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
220
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
140
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
180
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.4k
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
6
3.1k
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
660
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
140
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
What We Talk About When We Talk About XP
m_seki
2
450
Featured
See All Featured
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
A better future with KSS
kneath
240
18k
GitHub's CSS Performance
jonrohan
1033
470k
WENDY [Excerpt]
tessaabrams
12
39k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
490
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
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" }
👏 ご清聴ありがとうございました 👏