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.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
78
Other Decks in Programming
See All in Programming
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
220
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
150
Inside Stream API
skrb
1
670
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
550
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.3k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
4
1.4k
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
230
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.6k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
460
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
150
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
280
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
2
690
Marketing to machines
jonoalderson
1
5.4k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Everyday Curiosity
cassininazir
0
230
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Into the Great Unknown - MozCon
thekraken
41
2.6k
Bash Introduction
62gerente
615
210k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
Test your architecture with Archunit
thirion
1
2.3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
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" }
👏 ご清聴ありがとうございました 👏