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
Musashi Tsunoda
May 08, 2024
Technology
14
0
Share
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
More Decks by Musashi Tsunoda
See All by Musashi Tsunoda
How I Stopped Using an External Monitor
kakudenbuzo
1
67
Other Decks in Technology
See All in Technology
個人の発見を、組織の知恵に 〜生成AI活用を"探索"から"組織の仕組み"へ〜
kintotechdev
2
590
Diagnosing performance problems without the guesswork
elenatanasoiu
0
150
AIを「創る」と「使う」の循環 — HRテックが実践するリアルなAI組織実装
taketo957
0
660
トークン数だけでは測れない — Claude Code 組織展開の効果検証から学んだこと
makikub
0
100
Dynamic Workersについて
yusukebe
2
570
速さだけじゃない! VoidZero ツールが移行先に選ばれる理由
mizdra
PRO
6
730
Cloud Run のアップデート 触ってみる&紹介
gre212
0
300
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
2
1.5k
AI活用を推進するために ファインディが下した、一つの小さな決断
starfish719
0
190
JJUG CCC 2026 Spring AI時代の開発こそ標準化を武器に! ― 方式・プロセス・プラットフォームの標準化
s27watanabe
2
670
Unlocking the Apps
pimterry
0
170
サイバーセキュリティ概論 / Introduction to Cybersecurity
ks91
PRO
0
120
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
940
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Accessibility Awareness
sabderemane
1
130
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Utilizing Notion as your number one productivity tool
mfonobong
4
310
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
560
Context Engineering - Making Every Token Count
addyosmani
9
930
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
240
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
280
Building an army of robots
kneath
306
46k
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