Slide 1

Slide 1 text

OpenAPI × LaravelͰ API։ൃΛ֨ஈʹศརʹ͢Δํ๏ PHPΧϯϑΝϨϯε 2021/10/03 @sun-yryr / גࣜձࣾΏΊΈ

Slide 2

Slide 2 text

ΏΔΏΔ / Taiyo Minagawa w גࣜձࣾΏΊΈ৽ଔೖࣾ w 4FSWFSTJEF&OHJOFFS΍ͬͯ·͢ɻ ܦྺ ޷͖ͳ͜ͱ w 4XJGU 4FSWFSTJEF $*$% w 75VCFS sun-yryr taittide taittide sunyryr ࣗݾ঺հ NOW→

Slide 3

Slide 3 text

ձࣾ঺հ NOW→

Slide 4

Slide 4 text

ձࣾ঺հ NOW→

Slide 5

Slide 5 text

ͪͳΈʹ… دΓಓ NOW→

Slide 6

Slide 6 text

໨࣍ • OpenAPI࢓༷ॻΛʮ࡞Δʯ • ൒ࣗಈੜ੒͢Δ • OpenAPI࢓༷ॻΛʮ࢖͏ʯ • E2EςετͷAssertʹ࢖͏ • FormRequestͷ୅ΘΓʹ࢖͏ • Ҋ݅Ͱ࢖ͬͯΈͨײ૝

Slide 7

Slide 7 text

OpenAPI࢓༷ॻΛ”൒”ࣗಈੜ੒͢Δ

Slide 8

Slide 8 text

൒ࣗಈੜ੒͢Δ NOW→

Slide 9

Slide 9 text

ར༻͢ΔϥΠϒϥϦ • laravel-openapi Φϓγϣϯͱͯ͠ • annotations ൒ࣗಈੜ੒͢Δ NOW→

Slide 10

Slide 10 text

vyuldashev/laravel-openapi • LaravelͷRoute৘ใͱɺphpdoc΍AttributesΛ࢖ͬͯOpenAPI ࢓༷ॻΛ࡞੒͢ΔϥΠϒϥϦ ൒ࣗಈੜ੒͢Δ NOW→

Slide 11

Slide 11 text

LaravelCollective/annotations • Laravelͷ͞·͟·ͳઃఆΛphpdocͰ͍͍ײ͡ʹ΍ͬͯ͘ΕΔ ϥΠϒϥϦ • ࠓճ͸RouteͷઃఆͷΈʹ࢖͍·͢ ൒ࣗಈੜ੒͢Δ NOW→

Slide 12

Slide 12 text

࢖͍ํ - Annotations

Slide 13

Slide 13 text

࢖͍ํ - Annotations ൒ࣗಈੜ੒͢Δ NOW→

Slide 14

Slide 14 text

࢖͍ํ - Annotations ൒ࣗಈੜ੒͢Δ NOW→

Slide 15

Slide 15 text

࢖͍ํ - laravel-openapi con fi g/app.php ൒ࣗಈੜ੒͢Δ NOW→

Slide 16

Slide 16 text

࢖͍ํ - laravel-openapi con fi g/openapi.php schema.json ൒ࣗಈੜ੒͢Δ NOW→

Slide 17

Slide 17 text

࢖͍ํ - laravel-openapi SwaggerUI ൒ࣗಈੜ੒͢Δ NOW→

Slide 18

Slide 18 text

࢖͍ํ - laravel-openapi ൒ࣗಈੜ੒͢Δ NOW→

Slide 19

Slide 19 text

࢖͍ํ - laravel-openapi ൒ࣗಈੜ੒͢Δ NOW→

Slide 20

Slide 20 text

࢖͍ํ - laravel-openapi ൒ࣗಈੜ੒͢Δ NOW→

Slide 21

Slide 21 text

PHPͳΒͰ͸ͷ࢖͍ํ ൒ࣗಈੜ੒͢Δ NOW→

Slide 22

Slide 22 text

PHPͳΒͰ͸ͷ࢖͍ํ ൒ࣗಈੜ੒͢Δ NOW→

Slide 23

Slide 23 text

PHPͳΒͰ͸ͷ࢖͍ํ ൒ࣗಈੜ੒͢Δ NOW→

Slide 24

Slide 24 text

AssertʹOpenAPI࢓༷ॻΛ࢖͏

Slide 25

Slide 25 text

OASͷϑΥʔϚοτࢦఆ • σʔλܕʢinteger, number, string, booleanʣ • ϑΥʔϚοτʢint32, double, date-time, binaryͳͲʣ • patternʢਖ਼نදݱʣ • ͦͷଞͷࢦఆʢ࠷খ஋, ࠷େ஋, จࣈྻͷ௕͞ͳͲʣ Assertʹ࢖͏ NOW→

Slide 26

Slide 26 text

created_at: ? 1633219200 2021-10-03T09:00:00+09:00 2021-10-03 09:00:00 2021/10/03 09:00:00 Assertʹ࢖͏ NOW→

Slide 27

Slide 27 text

E2EςετͷAssertʹOpenAPIΛ࢖͏

Slide 28

Slide 28 text

༻ޠ ࠓճͷE2Eςετͱ͸ • ࠓճͷE2Eςετ͸୯७ʹAPIϦΫΤετΛߦ͍ɺͦͷϨεϙϯ εΛνΣοΫ͢Δςετͷ͜ͱΛࢦ͍ͯ͠·͢ • ଏʹݴ͏APIςετ • :sorry: E2Eʹ࢖͏ NOW→

Slide 29

Slide 29 text

Α͋͘Δςετ E2Eʹ࢖͏ NOW→

Slide 30

Slide 30 text

঺հ͢Δςετ E2Eʹ࢖͏ NOW→

Slide 31

Slide 31 text

thephpleague/openapi-psr7-validator • OpenAPI࢓༷ॻ͔ΒvalidatorΛੜ੒͢ΔϥΠϒϥϦ ͜Ε͚ͩͰOK

Slide 32

Slide 32 text

঺հ͢Δςετ E2Eʹ࢖͏ NOW→

Slide 33

Slide 33 text

঺հ͢Δςετ E2Eʹ࢖͏ NOW→

Slide 34

Slide 34 text

E2Eʹ࢖͏ NOW→

Slide 35

Slide 35 text

ValidationͰ͖Δ಺༰ • σʔλܕʢis_stringͳͲɺis_ʓʓϝιουʹରԠʣ • ϑΥʔϚοτʢdouble, date-time, emailͳͲʣ • patternʢͦͷ··preg_matchΛར༻ʣ • ࠷খ஋, ࠷େ஋, จࣈྻͷ௕͞, enumͳͲ E2Eʹ࢖͏ NOW→

Slide 36

Slide 36 text

͓͢͢Ί఺ • OpenAPI࢓༷ॻʹԊ͍ͬͯΔ͜ͱ͕อূ͞ΕΔ • ςετͷͨΊʹOpenAPI࢓༷ॻΛৄ͘͠ॻ͘͜ͱʹͳΔͷͰɺ APIར༻ऀଆͱᴥᴪ͕ى͖ͮΒ͍ + ϞοΫ΁ͷྲྀ༻˓ • E2EςετͷAssertͷྔ͕ݮΔ E2Eʹ࢖͏ NOW→

Slide 37

Slide 37 text

໰୊఺ • OpenAPI࢓༷ॻΛಡΈࠐΉॲཧͷίετ͕େ͖͍ • ݱঢ়ͷ࣮૷ͩͱςετΫϥε͝ͱʹಡΈࠐΈ͕૸ΔͷͰɺେن ໛ͳҊ݅ʹͳΔͱςετ͕ॏ͘ͳͬͯ͠·͏ • ஋ͦͷ΋ͷ͕ͦΕͰ͋Δ͜ͱͷνΣοΫ͸Ͱ͖ͳ͍ E2Eʹ࢖͏ NOW→

Slide 38

Slide 38 text

FormRequestͷ୅ΘΓʹOpenAPIΛ࢖͏

Slide 39

Slide 39 text

FormRequestʹ࢖͏ NOW→

Slide 40

Slide 40 text

͓͢͢Ί఺ • όϦσʔγϣϯΛOpenAPI࢓༷ॻʹ౷ҰͰ͖Δ 
 ʢೋॏ؅ཧʹͳΒͳ͍ʣ • FormRequestΛॻ͔ͳ͍͍ͯ͘ FormRequestʹ࢖͏ NOW→

Slide 41

Slide 41 text

໰୊఺ • ಡΈࠐΈ͕ωοΫʹͳΔɻࠓճ͸ϦΫΤετ͝ͱʹ૸ΔͷͰ༨ ܭҙࣝ͢Δඞཁ͕͋Δ • existͳͲlaravelͷศརͳόϦσʔγϣϯ͕࢖͑ͳ͍ • messageͷੜ੒͕Ͱ͖ͳ͍ • લॲཧɾޙॲཧΛ࣮૷͢Δʹ͸FormRequest͕ඞཁʹͳΔ FormRequestʹ࢖͏ NOW→

Slide 42

Slide 42 text

Ҋ݅Ͱ࢖ͬͯΈͨײ૝ OpenAPIͷ൒ࣗಈੜ੒ͱE2EςετͷAssertʹ͍ͭͯ

Slide 43

Slide 43 text

• ൒ࣗಈੜ੒ͱGUIπʔϧ͸ਖ਼௚Ͳ͍ͬ͜Ͳ͍ͬ͜ • Ωʔ໊΍ίϝϯτͷ౷Ұͷ࣮૷Λ͖ͪΜͱ΍Ε͹ɺ൒ࣗಈੜ੒ ͷํ͕ศར • ·ͩ੒௕தͷOSSͳͷͰɺ಺෦࣮૷ΛಡΜͰ͍Δਓ͕1ਓ͸ཉ ͍͠ ൒ࣗಈੜ੒ʹ͍ͭͯ ײ૝ NOW→

Slide 44

Slide 44 text

E2EͷAssertʹ͍ͭͯ • ࠓޙ࢖Θͳ͍ཧ༝͕ͳ͍͘Β͍ศརͩͬͨ • Assertͷྔ͕ݮΔͷຊ౰ʹ࠷ߴ • ઌʹOpenAPI࢓༷ॻ͕͋Δ৔߹Ͱ΋࢖͑Δ • ࢓༷ॻ͕όάͬͯΔͱςετ΋όάͬͯΔ͜ͱʹͳΔ ײ૝ NOW→

Slide 45

Slide 45 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ ࠓճͷαϯϓϧίʔυ͸ͪ͜Β