Upgrade to Pro — share decks privately, control downloads, hide ads and more …

phpcon2021-openapi

 phpcon2021-openapi

Eabc3d48a76f6827e35a4cd0a44008b3?s=128

ゆるゆる

October 03, 2021
Tweet

Transcript

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

  2. ΏΔΏΔ / Taiyo Minagawa w גࣜձࣾΏΊΈ৽ଔೖࣾ w 4FSWFSTJEF&OHJOFFS΍ͬͯ·͢ɻ ܦྺ ޷͖ͳ͜ͱ

    w 4XJGU 4FSWFSTJEF $*$% w 75VCFS sun-yryr taittide taittide sunyryr  ࣗݾ঺հ NOW→
  3.  ձࣾ঺հ NOW→

  4.  ձࣾ঺հ NOW→

  5. ͪͳΈʹ…  دΓಓ NOW→

  6. ໨࣍ • OpenAPI࢓༷ॻΛʮ࡞Δʯ • ൒ࣗಈੜ੒͢Δ • OpenAPI࢓༷ॻΛʮ࢖͏ʯ • E2EςετͷAssertʹ࢖͏ •

    FormRequestͷ୅ΘΓʹ࢖͏ • Ҋ݅Ͱ࢖ͬͯΈͨײ૝ 
  7. OpenAPI࢓༷ॻΛ”൒”ࣗಈੜ੒͢Δ 

  8.  ൒ࣗಈੜ੒͢Δ NOW→

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

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

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

  12. ࢖͍ํ - Annotations <?ph p namespace App\Providers ; use Collective\Annotations\AnnotationsServiceProvider

    as ServiceProvider ; class AnnotationsServiceProvider extends ServiceProvider { protected $scanEvents = [] ; protected $scanRoutes = [] ; protected $scanModels = [] ; protected $scanWhenLocal = false ; protected $scanControllers = true ; protected $scanEverything = false ; }  ൒ࣗಈੜ੒͢Δ NOW→
  13.  ࢖͍ํ - Annotations ൒ࣗಈੜ੒͢Δ NOW→

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

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

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

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

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

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

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

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

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

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

  24. AssertʹOpenAPI࢓༷ॻΛ࢖͏ 

  25. OASͷϑΥʔϚοτࢦఆ • σʔλܕʢinteger, number, string, booleanʣ • ϑΥʔϚοτʢint32, double, date-time,

    binaryͳͲʣ • patternʢਖ਼نදݱʣ • ͦͷଞͷࢦఆʢ࠷খ஋, ࠷େ஋, จࣈྻͷ௕͞ͳͲʣ  Assertʹ࢖͏ NOW→
  26.  created_at: ? 1633219200 2021-10-03T09:00:00+09:00 2021-10-03 09:00:00 2021/10/03 09:00:00 Assertʹ࢖͏

    NOW→
  27. E2EςετͷAssertʹOpenAPIΛ࢖͏ 

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

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

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

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

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

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

  34.  E2Eʹ࢖͏ NOW→

  35. ValidationͰ͖Δ಺༰ • σʔλܕʢis_stringͳͲɺis_ʓʓϝιουʹରԠʣ • ϑΥʔϚοτʢdouble, date-time, emailͳͲʣ • patternʢͦͷ··preg_matchΛར༻ʣ •

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

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

    NOW→
  38. FormRequestͷ୅ΘΓʹOpenAPIΛ࢖͏ 

  39.  FormRequestʹ࢖͏ NOW→

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

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

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

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

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

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