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
Compiler APIを利用して TypeScriptのAPI型定義ファイルからOpenAP...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Musashi Tsunoda
May 08, 2024
Technology
0
13
Compiler APIを利用して TypeScriptのAPI型定義ファイルからOpenAPI.jsonを作成する/Create OpenAPI.json from a TypeScript API type definition file using the Compiler API
Musashi Tsunoda
May 08, 2024
Tweet
Share
More Decks by Musashi Tsunoda
See All by Musashi Tsunoda
How I Stopped Using an External Monitor
kakudenbuzo
1
61
Other Decks in Technology
See All in Technology
AWS DevOps Agent vs SRE俺 / AWS DevOps Agent vs me, the SRE
sms_tech
3
890
20260311 技術SWG活動報告(デジタルアイデンティティ人材育成推進WG Ph2 活動報告会)
oidfj
0
360
Cortex Code CLI と一緒に進めるAgentic Data Engineering
__allllllllez__
0
410
システム標準化PMOから ガバメントクラウドCoEへ
techniczna
1
130
バクラク最古参プロダクトで重ねた技術投資を振り返る
ypresto
0
170
OSC仙台プレ勉強会 AlmaLinuxとは
koedoyoshida
0
190
Keycloak を使った SSO で CockroachDB にログインする / CockroachDB SSO with Keycloak
kota2and3kan
0
160
AI時代のSaaSとETL
shoe116
1
180
スクリプトの先へ!AIエージェントと組み合わせる モバイルE2Eテスト
error96num
0
180
OpenClaw を Amazon Lightsail で動かす理由
uechishingo
0
180
モジュラモノリス導入から4年間の総括:アーキテクチャと組織の相互作用について / Architecture and Organizational Interaction
nazonohito51
1
130
スケールアップ企業でQA組織が機能し続けるための組織設計と仕組み〜ボトムアップとトップダウンを両輪としたアプローチ〜
tarappo
1
150
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Practical Orchestrator
shlominoach
191
11k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
110
Google's AI Overviews - The New Search
badams
0
930
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
150
Documentation Writing (for coders)
carmenintech
77
5.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
WCS-LA-2024
lcolladotor
0
480
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
250
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
150
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.1k
Transcript
Compiler APIΛར༻ͯ͠ APIܕఆٛϑΝΠϧ͔Β OpenAPI.jsonΛ࡞͢Δ TypeScript Developers Meetup ʙϑϩϯτ͔ΒόοΫ·Ͱ TSʙ
2024/05/08
AGENDA 1. ࣗݾհ 2. Communeͷٕज़ελοΫ 3. Communeʹ͓͚ΔAPIͷܕఆٛ 4. ࠷ۙͷ՝ 5.
APIܕఆٛϑΝΠϧ͔ΒOpenAPI.jsonΛ࡞ 6. ࠓޙͷ՝ 7. ·ͱΊ
© Commune Inc. All rights reserved ֯ాଂ (a.k.a. Buzo) Tech
& Platform Software engineer Musashi Tsunoda ڈͷ8݄ʹίϛϡʔϯגࣜձࣾʹೖࣾɻ TypeScriptʹΑΔόοΫΤϯυɾϑϩϯτΤϯυ྆ ํͷ։ൃΛߦ͏ɻ ུ֓ SNS X: @buzou_muzou ࣗݾհ ͖ͳ͜ͱ ݸਓ։ൃͱϘΫγϯά
Communeͷٕज़ελοΫ
© Commune Inc. All rights reserved Communeͷٕज़ελοΫ όοΫΤϯυ ϞόΠϧΞϓϦ ϑϩϯτΤϯυ
© Commune Inc. All rights reserved • WebTypeScriptͰ౷Ұ ◦ ֶशίετ͕͍
◦ ࠾༻ͷ໘ͰͷΤϯδχΞͷ֬อͷ༏Ґੑ ◦ ܕఆٛϑΝΠϧͷڞ༗ʹΑΔ։ൃͷޮԽ • ϞόΠϧFlutter ◦ ΫϩεϓϥοτϑΥʔϜͳ։ൃ Communeͷٕज़ελοΫ
Communeʹ͓͚Δ APIͷܕఆٛ
© Commune Inc. All rights reserved όοΫΤϯυɾϑϩϯτΤϯυͰAPIͷܕఆٛͷڞ༗ Communeʹ͓͚ΔAPIͷܕఆٛ
࠷ۙͷ՝
© Commune Inc. All rights reserved • APIͷฦ٫ͷϥϯλΠϜͰͷܕͷෆҰக ◦ booleanͷ͕ͣ
0 or 1ʹͳ͍ͬͯΔ ◦ numberͷ͕ͣstringʹͳ͍ͬͯΔ ◦ etc • ϞόΠϧνʔϜͱͷ࿈ܞ ◦ APIΤϯυϙΠϯτͷ ৽ن࡞ɾ༷มߋ࣌ͷೝࣝͣΕ ࠷ۙͷ՝
OpenAPI.jsonΛ࡞Ζ͏
© Commune Inc. All rights reserved • Compiler APIͰAPIܕఆ͔ٛΒOpenAPI.jsonΛ࡞͢Δ ◦
εΩʔϚۦಈͷAPI։ൃʹγϑτ ◦ ϞόΠϧνʔϜͱͷ࿈ܞʹ༻ • OpenAPI.jsonΛݩʹೖग़ྗͷܕνΣοΫΛಋೖ ◦ ϥϯλΠϜͷϦΫΤετͱϨεϙϯεͷܕΛอূ ํ
Compiler APIͱ
© Commune Inc. All rights reserved Compilier APIͱ • TypeScriptͷτϥϯεύΠϧ࣌ʹߦ͍ͬͯΔΑ͏ͳॲཧΛ
ݺͼग़͢͜ͱ͕Ͱ͖ΔAPI • ίʔυΛநߏจ(AST)ͱͯ͠ղੳ͕Ͱ͖Δ • ίʔυͷมࣗಈੜͳͲʹར༻͢Δ͜ͱ͕Ͱ͖Δ • Web APIͰͳ͍ • TypeScriptͷ։ൃݩ͕ެ։͍ͯ͠Δ https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
Compiler APIΛͬͯ OpenAPI.jsonΛ࡞͢Δ
© Commune Inc. All rights reserved ΰʔϧ: APIܕఆٛϑΝΠϧ͔ΒOpenAPI.jsonΛ࡞ OpenAPI.jsonΛ࡞
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ Tsunagger *ʮͭͳ͙ +
Swaggerʯ͔Β໋໊ *Tsunoda(ࢲͷ໊લ)ͱҰؔͳ͍ OpenAPI.json͕ੜͰ͖ΔεΫϦϓτΛ࡞ npm run tsunagger Ͱ
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ CommuneͷAPIܕఆٛϑΝΠϧ • Type͕HTTPϝιου໊
◦ ΤϯυϙΠϯτύε໊ ▪ ϦΫΤετͷܕఆٛ ▪ Ϩεϙϯεͷܕఆٛ
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ • ΤϯυϙΠϯτͷύε໊͝ͱ ◦
HTTPϝιου໊ ▪ ϦΫΤετͷܕఆٛ ▪ Ϩεϙϯεͷܕఆٛ OpenAPIʹΑΔAPIεΩʔϚఆٛ
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ foo: string “foo”:
{“type”:”string”}, bar: number “bar”: {“type”:“number”} baz: { foo: string, bar: number } “baz”: { “type”: “object”, "properties": { “foo”: {“type”:”string”}, “bar”: {“type”:“number”} } } TypeScript OpenAPI.json
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ Compiler APIΛۦͯ͠ɺ TSͷநߏจ͔ΒܕఆٛΛղੳ͍ͯ͘͠
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ https://ts-ast-viewer.com/
© Commune Inc. All rights reserved 1. TSϑΝΠϧͷಡΈࠐΈ 2. ts.SourceFileϑΝΠϧΦϒδΣΫτͷੜ
3. ֤ϊʔυͰܕͷγϯϘϧΛऔಘ a. ObjectArrayܕͷ߹ ͞ΒʹͦͷࢠϊʔυͷܕͷγϯϘϧΛऔಘ 4. OpenAPI.jsonͷܗࣜʹͯ͠ϑΝΠϧʹग़ྗ OpenAPI.jsonΛ࡞ TsunaggerͷॲཧͷྲྀΕ
© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞ OpenAPI.jsonͷ࡞ͷࣗಈԽʹޭ! ͦΕʹΑΓҎԼ͕࣮ݱͨ͠ •
Swagger UIͰOpenAPI.jsonΛݩʹAPI༷ॻͷڞ༗ • openapi-request-validatorΛ༻͍ͨ APIͷres/reqόϦσʔγϣϯ
© Commune Inc. All rights reserved มॲཧͰ٧·ͬͨՕॴ • Class •
ϢχΦϯܕ • ॥ࢀরʹͳ͍ͬͯΔܕ • τϦοΩʔͳܕఆٛ ݸผʹରԠՄೳ͕ͩɺͦͷίʔυෳࡶʹͳ͍ͬͯ͘ɻɻɻ APIͷreq/resͷఆٛఆ͕ٛҎԼͷΑ͏ͳ߹
ࠓޙͷ՝
© Commune Inc. All rights reserved ࠓޙͷ՝ • Tsunaggerͷอक •
୯७ͳΦϒδΣΫτ ϓϦϛςΟϒͳܕఆٛͰͳ͍߹ͷରॲ • ผͷํ๏ͷݕ౼ ◦ APIܕఆٛΛzodͰߦ͍ɺzod-to-openapi ֎෦ϥΠϒϥϦͰOpenAPI.jsonΛ࡞ ◦ zodͷҠߦظؒதTsunaggerʹΑΔOpenAPI.jsonΛ ར༻͢Δ༧ఆ
·ͱΊ
© Commune Inc. All rights reserved • ϑϩϯτΤϯυͱόοΫΤϯυͰ APIͷܕఆٛϑΝΠϧΛڞ༗͍ͯ͠Δ ·ͱΊ
• ϞόΠϧͱͷ࿈ܞͷͨΊʹOpenAPI.json͕ඞཁʹͳͬͨ • Compiler APIΛར༻͠ɺ TSͷܕఆٛϑΝΠϧ͔ΒOpenAPI.json͕࡞Ͱ͖ͨ • ୯७Ͱͳ͍ܕఆٛͷมՄೳͰ͋Δ͕ίʔυ͕ෳࡶʹͳΔ
࠷ޙʹએͰ͢📢
© Commune Inc. All rights reserved 31 ίϛϡʔϯ͋ͳͨͷΩϟϦΞΛ࣮ݱ͢ΔϏʔΫϧͰ͢ʂ XΞΧϯτ @CommuneDev
ϑΥϩʔ͓ئ͍͠·͢! ΤϯδχΞ͚ձࣾใ https://commmune.notion.site/ver- 0b895a0187ef4954a2d5182afd82082d
32 © Commune Inc. All rights reserved