Slide 1

Slide 1 text

Compiler APIΛར༻ͯ͠ APIܕఆٛϑΝΠϧ͔Β
 OpenAPI.jsonΛ࡞੒͢Δ TypeScript Developers Meetup 
 ʙϑϩϯτ͔ΒόοΫ·Ͱ TSʙ 2024/05/08

Slide 2

Slide 2 text

AGENDA 1. ࣗݾ঺հ 2. Communeͷٕज़ελοΫ 3. Communeʹ͓͚ΔAPIͷܕఆٛ 4. ࠷ۙͷ՝୊ 5. APIܕఆٛϑΝΠϧ͔ΒOpenAPI.jsonΛ࡞੒ 6. ࠓޙͷ՝୊ 7. ·ͱΊ

Slide 3

Slide 3 text

© Commune Inc. All rights reserved ֯ా෢ଂ (a.k.a. Buzo) Tech & Platform Software engineer Musashi Tsunoda ڈ೥ͷ8݄ʹίϛϡʔϯגࣜձࣾʹೖࣾɻ TypeScriptʹΑΔόοΫΤϯυɾϑϩϯτΤϯυ྆ ํͷ։ൃΛߦ͏ɻ ུ֓ SNS X: @buzou_muzou ࣗݾ঺հ ޷͖ͳ͜ͱ ݸਓ։ൃͱϘΫγϯά

Slide 4

Slide 4 text

Communeͷٕज़ελοΫ

Slide 5

Slide 5 text

© Commune Inc. All rights reserved Communeͷٕज़ελοΫ όοΫΤϯυ ϞόΠϧΞϓϦ ϑϩϯτΤϯυ

Slide 6

Slide 6 text

© Commune Inc. All rights reserved ● Web͸TypeScriptͰ౷Ұ ○ ֶशίετ͕௿͍ ○ ࠾༻ͷ໘ͰͷΤϯδχΞͷ֬อͷ༏Ґੑ ○ ܕఆٛϑΝΠϧͷڞ༗ʹΑΔ։ൃͷޮ཰Խ ● ϞόΠϧ͸Flutter ○ ΫϩεϓϥοτϑΥʔϜͳ։ൃ Communeͷٕज़ελοΫ

Slide 7

Slide 7 text

Communeʹ͓͚Δ APIͷܕఆٛ

Slide 8

Slide 8 text

© Commune Inc. All rights reserved όοΫΤϯυɾϑϩϯτΤϯυͰAPIͷܕఆٛͷڞ༗ Communeʹ͓͚ΔAPIͷܕఆٛ

Slide 9

Slide 9 text

࠷ۙͷ՝୊

Slide 10

Slide 10 text

© Commune Inc. All rights reserved ● APIͷฦ٫஋ͷϥϯλΠϜͰͷܕͷෆҰக ○ booleanͷ͸͕ͣ 0 or 1ʹͳ͍ͬͯΔ ○ numberͷ͸͕ͣstringʹͳ͍ͬͯΔ ○ etc ● ϞόΠϧνʔϜͱͷ࿈ܞ ○ APIΤϯυϙΠϯτͷ
 ৽ن࡞੒ɾ࢓༷มߋ࣌ͷೝࣝͣΕ ࠷ۙͷ՝୊

Slide 11

Slide 11 text

OpenAPI.jsonΛ࡞Ζ͏

Slide 12

Slide 12 text

© Commune Inc. All rights reserved ● Compiler APIͰAPIܕఆ͔ٛΒOpenAPI.jsonΛ࡞੒͢Δ ○ εΩʔϚۦಈͷAPI։ൃʹγϑτ ○ ϞόΠϧνʔϜͱͷ࿈ܞʹ࢖༻ ● OpenAPI.jsonΛݩʹೖग़ྗͷܕνΣοΫΛಋೖ ○ ϥϯλΠϜͷϦΫΤετͱϨεϙϯεͷܕΛอূ ํ਑

Slide 13

Slide 13 text

Compiler APIͱ͸

Slide 14

Slide 14 text

© Commune Inc. All rights reserved Compilier APIͱ͸ ● TypeScriptͷτϥϯεύΠϧ࣌ʹߦ͍ͬͯΔΑ͏ͳॲཧΛ
 ݺͼग़͢͜ͱ͕Ͱ͖ΔAPI ● ίʔυΛந৅ߏจ໦(AST)ͱͯ͠ղੳ͕Ͱ͖Δ ● ίʔυͷม׵΍ࣗಈੜ੒ͳͲʹར༻͢Δ͜ͱ͕Ͱ͖Δ ● Web APIͰ͸ͳ͍ ● TypeScriptͷ։ൃݩ͕ެ։͍ͯ͠Δ
 https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

Slide 15

Slide 15 text

Compiler APIΛ࢖ͬͯ OpenAPI.jsonΛ࡞੒͢Δ

Slide 16

Slide 16 text

© Commune Inc. All rights reserved ΰʔϧ: APIܕఆٛϑΝΠϧ͔ΒOpenAPI.jsonΛ࡞੒ OpenAPI.jsonΛ࡞੒

Slide 17

Slide 17 text

© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞੒ Tsunagger *ʮͭͳ͙ + Swaggerʯ͔Β໋໊ *Tsunoda(ࢲͷ໊લ)ͱ͸Ұ੾ؔ܎ͳ͍ OpenAPI.json͕ੜ੒Ͱ͖ΔεΫϦϓτΛ࡞੒ npm run tsunagger Ͱ

Slide 18

Slide 18 text

© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞੒ CommuneͷAPIܕఆٛϑΝΠϧ ● Type͕HTTPϝιου໊ ○ ΤϯυϙΠϯτύε໊ ■ ϦΫΤετͷܕఆٛ ■ Ϩεϙϯεͷܕఆٛ

Slide 19

Slide 19 text

© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞੒ ● ΤϯυϙΠϯτͷύε໊͝ͱ ○ HTTPϝιου໊ ■ ϦΫΤετͷܕఆٛ ■ Ϩεϙϯεͷܕఆٛ OpenAPIʹΑΔAPIεΩʔϚఆٛ

Slide 20

Slide 20 text

© 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

Slide 21

Slide 21 text

© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞੒ Compiler APIΛۦ࢖ͯ͠ɺ
 TSͷந৅ߏจ໦͔ΒܕఆٛΛղੳ͍ͯ͘͠

Slide 22

Slide 22 text

© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞੒ https://ts-ast-viewer.com/

Slide 23

Slide 23 text

© Commune Inc. All rights reserved 1. TSϑΝΠϧͷಡΈࠐΈ 2. ts.SourceFileϑΝΠϧΦϒδΣΫτͷੜ੒ 3. ֤ϊʔυͰܕͷγϯϘϧΛऔಘ a. Object΍Arrayܕͷ৔߹͸
 ͞ΒʹͦͷࢠϊʔυͷܕͷγϯϘϧΛऔಘ 4. OpenAPI.jsonͷܗࣜʹͯ͠ϑΝΠϧʹग़ྗ OpenAPI.jsonΛ࡞੒ TsunaggerͷॲཧͷྲྀΕ

Slide 24

Slide 24 text

© Commune Inc. All rights reserved OpenAPI.jsonΛ࡞੒ OpenAPI.jsonͷ࡞੒ͷࣗಈԽʹ੒ޭ! ͦΕʹΑΓҎԼ͕࣮ݱͨ͠ ● Swagger UIͰOpenAPI.jsonΛݩʹAPI࢓༷ॻͷڞ༗ ● openapi-request-validatorΛ༻͍ͨ
 APIͷres/reqόϦσʔγϣϯ

Slide 25

Slide 25 text

© Commune Inc. All rights reserved ม׵ॲཧͰ٧·ͬͨՕॴ ● Class ● ϢχΦϯܕ ● ॥؀ࢀরʹͳ͍ͬͯΔܕ ● τϦοΩʔͳܕఆٛ ݸผʹରԠ͸Մೳ͕ͩɺͦͷ෼ίʔυ͸ෳࡶʹͳ͍ͬͯ͘ɻɻɻ APIͷreq/resͷఆٛఆ͕ٛҎԼͷΑ͏ͳ৔߹

Slide 26

Slide 26 text

ࠓޙͷ՝୊

Slide 27

Slide 27 text

© Commune Inc. All rights reserved ࠓޙͷ՝୊ ● Tsunaggerͷอक ● ୯७ͳΦϒδΣΫτ΍
 ϓϦϛςΟϒͳܕఆٛͰ͸ͳ͍৔߹ͷରॲ ● ผͷํ๏ͷݕ౼ ○ APIܕఆٛΛzodͰߦ͍ɺzod-to-openapi౳
 ֎෦ϥΠϒϥϦͰOpenAPI.jsonΛ࡞੒ ○ zod΁ͷҠߦظؒத͸TsunaggerʹΑΔOpenAPI.jsonΛ
 ར༻͢Δ༧ఆ

Slide 28

Slide 28 text

·ͱΊ

Slide 29

Slide 29 text

© Commune Inc. All rights reserved ● ϑϩϯτΤϯυͱόοΫΤϯυͰ͸
 APIͷܕఆٛϑΝΠϧΛڞ༗͍ͯ͠Δ ·ͱΊ ● ϞόΠϧͱͷ࿈ܞͷͨΊʹOpenAPI.json͕ඞཁʹͳͬͨ ● Compiler APIΛར༻͠ɺ
 TSͷܕఆٛϑΝΠϧ͔ΒOpenAPI.json͕࡞੒Ͱ͖ͨ ● ୯७Ͱͳ͍ܕఆٛͷม׵͸ՄೳͰ͋Δ͕ίʔυ͕ෳࡶʹͳΔ

Slide 30

Slide 30 text

࠷ޙʹએ఻Ͱ͢📢

Slide 31

Slide 31 text

© Commune Inc. All rights reserved 31 ίϛϡʔϯ͸͋ͳͨͷΩϟϦΞΛ࣮ݱ͢ΔϏʔΫϧͰ͢ʂ XΞΧ΢ϯτ @CommuneDev ϑΥϩʔ͓ئ͍͠·͢! ΤϯδχΞ޲͚ձࣾ৘ใ https://commmune.notion.site/ver- 0b895a0187ef4954a2d5182afd82082d

Slide 32

Slide 32 text

32 © Commune Inc. All rights reserved