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
13
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
62
Other Decks in Technology
See All in Technology
20260423_執筆の工夫と裏側 技術書の企画から刊行まで / From the planning to the publication of technical book
nash_efp
3
410
M5Stack CoreS3とZephyr(RTOS)で Edge AIっぽいことしてみた
iotengineer22
0
250
コードや知識を組み込む / Incorporate Code and Knowledge
ks91
PRO
0
160
AWS認定資格は本当に意味があるのか?
nrinetcom
PRO
2
280
AI: Making Admin and Users, Lives Better
kbmsg
0
100
Rebirth of Software Craftsmanship in the AI Era
lemiorhan
PRO
4
2.1k
Amazon S3 Filesについて
yama3133
2
210
AIでAIをテストする - 音声AIエージェントの品質保証戦略
morix1500
1
120
AIはハッカーを減らすのか、増やすのか?──現役ホワイトハッカーから見るAI時代のリアル【MEGU-Meet】
cscengineer
0
170
AIが書いたコードを信じられない問題 〜レビュー負荷を下げるために変えたこと〜 / The AI Code Trust Gap: Reducing the Review Burden
bitkey
PRO
8
1.3k
弁護士ドットコム株式会社 エンジニア職向け 会社紹介資料
bengo4com
1
160
プラットフォームエンジニアリングの実践 - AWS コンテナサービスで構築する社内プラットフォーム / AWS Containers Platform Meetup #1
literalice
1
200
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
So, you think you're a good person
axbom
PRO
2
2k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
53k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.4k
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
270
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.6k
Practical Orchestrator
shlominoach
191
11k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.4k
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