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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
(技術的には)社内システムもOKなブラウザエージェントを作ってみた!
har1101
0
340
【Oracle Cloud ウェビナー】[Oracle AI Database + AWS] Oracle Database@AWSで広がるクラウドの新たな選択肢とAI時代のデータ戦略
oracle4engineer
PRO
2
190
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
260
今こそ学びたいKubernetesネットワーク ~CNIが繋ぐNWとプラットフォームの「フラッと」な対話
logica0419
5
540
AIエージェントを開発しよう!-AgentCore活用の勘所-
yukiogawa
0
190
ClickHouseはどのように大規模データを活用したAIエージェントを全社展開しているのか
mikimatsumoto
0
270
SREのプラクティスを用いた3領域同時 マネジメントへの挑戦 〜SRE・情シス・セキュリティを統合した チーム運営術〜
coconala_engineer
2
780
Ruby版 JSXのRuxが気になる
sansantech
PRO
0
170
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
配列に見る bash と zsh の違い
kazzpapa3
3
170
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
130
GitHub Issue Templates + Coding Agentで簡単みんなでIaC/Easy IaC for Everyone with GitHub Issue Templates + Coding Agent
aeonpeople
1
260
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
260
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
280
Documentation Writing (for coders)
carmenintech
77
5.3k
The Spectacular Lies of Maps
axbom
PRO
1
530
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
100
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
130
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
57
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Are puppies a ranking factor?
jonoalderson
1
2.7k
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