Save 37% off PRO during our Black Friday Sale! »

SchemaDrivenDevelopment

 SchemaDrivenDevelopment

B6a35c859bb72c6135f6c5d4a8bad402?s=128

atomiyama

March 24, 2021
Tweet

Transcript

  1. Copyright 2018 Studyplus, Inc. All Rights Reserved. OpenAPIΛ༻͍ͨεΩʔϚۦಈ։ൃ Akifumi Tomiyama

    / Studyplus Inc . 2021.03.24 @γϡʔϚΠʂ
  2. ࣗݾ঺հ ✎ 2018/09~ Studyplusೖࣾ ✎ 29ࡀ ✎ ؠखݝࡏॅ ✎ ޷͖ͳݴޠɿRuby,

    Rust ෌ࢁথ࢙ Akifumi Tomiyama atomiyama atomiyama1216 Studyplus Inc. ForSchool Dept. 
 CX Product Group Team Lead.
  3. ձࣾ঺հ About Us

  4. MISSION ʮֶͿتͼΛ͢΂ͯͷਓ΁ʯ ଟ͘ͷਓ͕StudyplusΛ௨ֶͯ͡शͷ͖͔͚ͬΛݟ͚ͭɺ ֶशΛָ͘͠ܧଓͰ͖Δ͜ͱΛ࣮ݱ͢Δɻ

  5. ֶशه࿥ͷՄࢹԽͱɺಉ͡໨ඪΛ໨ࢦ͢஥ؒͱͷSNSͰϞνϕʔγϣϯΛܧଓͰ͖·͢ɻ ΞϓϦϨϏϡʔฏۉ4.5Ҏ্ɻGoogle Play2೥࿈ଓϕετΞϓϦɺ೔ຊe-Learningେ৆ʢ࠷༏ल৆ʣͳͲड৆ଟ਺ɻ ʮຖ೔ͷษڧΛश׳ʹͰ͖ͳ͍ʯ೰ΈΛղܾ

  6. ࢀߟॻಡΈ์୊ΞϓϦͷϙϧτ͸ɺ डݧੜʹਓؾͷࢀߟॻΛֹ݄980ԁʢ੫ผʣͰεϚϗͰಡΈ์୊ͷɺిࢠࢀߟॻͷαϒεΫϦϓγϣϯαʔϏεͰ͢ɻ ਓؾࢀߟॻΛεϚϗͰಡΈ์୊ͷɺిࢠࢀߟॻΞϓϦ

  7. Studyplus for School͸ɺڭҭػؔ޲ֶ͚श؅ཧαʔϏεͰ͢ɻ ੜెͷ೔ʑͷ౒ྗΛɺؾ͖ͮɺ๙ΊΔػೳΛଟ਺ἧ͍͑ͯ·͢ɻ SNSͷΑ͏ͳૢ࡞ײͰɺ ୭Ͱ΋͙͢ʹ࢖͍͸͡ΊΒΕ·͢ɻ ઌੜ͕ੜెΛ๙ΊΔػձΛ࠷େԽ͢Δɺֶशक़ͷ৽͍͠ελϯμʔυ

  8. OpenAPIΛ༻͍ͨεΩʔϚۦಈ։ൃ Schema Driven Development

  9. ࿩͢͜ͱ • OpenAPI 3.0ͱcommitteeΛ࢖ͬͨ։ൃͷ࿩ • εΩʔϚۦಈ։ൃͷྲྀΕ • εΩʔϚϑΝΠϧ؅ཧ • ࠓ๊͍͑ͯΔ՝୊

  10. Studyplus for SchoolͷγεςϜ • APIαʔόʔ • Rails • ΫϥΠΞϯτ •

    React • Elm • Next.js
  11. Studyplus for Schoolͷ։ൃମ੍ • εΫϥϜ։ൃ • 9໊ମ੍ • 2week /

    sprint • ։ൃϝϯόʔ • 6໊
  12. Studyplus for Schoolͷ։ൃϑϩʔ ͜͜Λ୹ظؒͰਐΊΔ

  13. چ࣮૷ϑϩʔ ͜͜ͷ଴ͪ࣌ؒΛ࠷খԽ͢Δ ͜͜ͷख໭ΓΛݮΒ͢

  14. ݱߦͷ࣮૷ϑϩʔ API։ൃஈ֊ͰFBΛ ड͚Δ͜ͱ͕Ͱ͖ɼ ख໭Γ͕গͳ͘ࡁΉ APIͷຊ࣮૷Λ ଴ͨͣϑϩϯτ։ൃΛ ։࢝Ͱ͖Δ

  15. ࢖͍ͬͯΔπʔϧ OpenAPI 3.0 
 REST APIΛఆٛ͢ΔͨΊඪ४࢓༷ Swagger UI 
 APIεΩʔϚͷ֬ೝ

    Gems • committee 
 ϦΫΤετɼϨεϙϯεόϦσʔγϣϯɼςετΞαʔγϣϯ • json_refs 
 ෳ਺ϑΝΠϧ؅ཧ࣌ͷrefͷղܾ
  16. Copyright (C) 2017 Studyplus, Inc. All Rights Reserved. Confidential APIઃܭ

  17. APIεΩʔϚఆٛ • OpenAPIͷ࢓༷ʹԊͬͯهड़ • yaml • ίϯτϩʔϥͷΞΫγϣϯʹ ରͯ͠1ϑΝΠϧͣͭʹ෼ׂ • ύϥϝʔλ΍ΤϥʔϨεϙϯ

    εͳͲ͸࠶ར༻ՄೳͳΑ͏ʹ ڞ௨Խ
  18. APIεΩʔϚఆٛϑΝΠϧ؅ཧ • main.yaml 
 ΞϓϦέʔγϣϯͷఆٛʢೝূͳͲ • paths.yamlɼpath/* 
 ΤϯυϙΠϯτͷఆٛ •

    schemas.yaml, schemas/* 
 ϦιʔεͷఆٛʢϞσϧͱରԠ • parameters.yaml, parameters/* 
 ڞ௨ύϥϝʔλͷఆٛ • responses.yaml, responses/* 
 ڞ௨Ϩεϙϯεͷఆٛ > tree -L 3 swagger/api/v1 ├── components │ ├── schemas.yaml │ ├── parameters.yaml │ ├── responses.yaml │ ├── parameters │ │ ├── section_id.yaml │ │ └── student_id.yaml │ ├── schemas │ │ ├── section.yaml │ │ └── student.yaml ├── paths │ └── sections │ └── index.yaml ├── paths.yaml └── main.yaml
  19. APIεΩʔϚఆٛϑΝΠϧ؅ཧ

  20. APIεΩʔϚఆٛϑΝΠϧ؅ཧ • main.yaml 
 ΞϓϦέʔγϣϯͷఆٛʢೝূͳͲ • paths.yamlɼpath/* 
 ΤϯυϙΠϯτͷఆٛ •

    schemas.yaml, schemas/* 
 ϦιʔεͷఆٛʢϞσϧͱରԠ • parameters.yaml, parameters/* 
 ڞ௨ύϥϝʔλͷఆٛ • responses.yaml, responses/* 
 ڞ௨Ϩεϙϯεͷఆٛ > tree -L 3 swagger/api/v1 ├── components │ ├── schemas.yaml │ ├── parameters.yaml │ ├── responses.yaml │ ├── parameters │ │ ├── section_id.yaml │ │ └── student_id.yaml │ ├── schemas │ │ ├── section.yaml │ │ └── student.yaml ├── paths │ └── sections │ └── index.yaml ├── paths.yaml └── main.yaml
  21. APIεΩʔϚఆٛϑΝΠϧ؅ཧ • JSONͰεΩʔϚΛฦ͢APIΛ࣮૷ • swagger-uiͰ͜ΕΛӾཡ͢Δ

  22. Copyright (C) 2017 Studyplus, Inc. All Rights Reserved. Confidential ϞοΫAPIͷ࡞੒

  23. ϞοΫAPIͷ࡞੒ • ͱΓ͋͑ͣಈ͘࠷খݶͷ࣮૷ 1.routeΛ௥Ճ 2.࠷௿ݶͷςετΛ௥Ճ 3.swagger-uiͷϨεϙϯεΛ 
 ίϯτϩʔϥʹϕλషΓ͢Δ 4.ίʔυϨϏϡʔ 


    εΩʔϚʹաෆ଍ແ͍͔֬ೝʂ 5.mergeͯ͠σϓϩΠ
  24. εΩʔϚόϦσʔγϣϯ • ࣮૷ͱεΩʔϚͷဃ཭๷ࢭ - request specͰอূ - ͢΂ͯͷϨεϙϯε͕ఆٛͱဃ཭͠ ͍ͯͳ͍͔assert_schema_conform Ͱ֬ೝ

    - ෳ਺ͷAPIʢ಺෦ެ։ɼ֎෦ެ։ʣ ͕͋ΔͷͰRSpecͷmetadataʹ OpenAPIఆٛϑΝΠϧύεΛࢦఆͰ ͖ΔΑ͏ʹ͍ͯ͠Δ
  25. ͜ͷ࣮૷ϑϩʔͰྑ͔ͬͨ͜ͱ • ϑϩϯτΤϯυ࡞ۀऀͷ଴ͪ࣌ؒΛ࡟ݮͰ͖ͨ • ϞοΫAPIͷ࡞੒࡞ۀ͸1~2࣌ؒͰ׬݁Ͱ͖Δ • API࣮૷ͷख໭ΓΛ࠷খԽͰ͖Δ • ຊ൪؀ڥద༻ޙʹमਖ਼͕ඞཁʹͳΔ͜ͱ͕ݮΒͤΔ •

    ։ൃॳظஈ֊͔Βαʔόʔͱϑϩϯτͷ࡞ۀऀͷೝࣝͷဃ཭͕ݮͬͨ • ϑϩϯτ࡞ۀऀͱαʔόʔ࡞ۀऀͰεΩʔϚϕʔεͰର࿩Ͱ͖Δ
  26. ݱঢ়ͷ՝୊ • enumͳͲͷ஋ʹରͯ͢͠΂ͯͷύλʔϯΛ໢ཏͨ͠ϞοΫAPIΛఏڙ͠ Α͏ͱ͢Δͱ໘౗ 
 →ݱঢ়ϑϩϯτଆʹ௥ՃͰϕλॻ͖ͨ͠Γͯ͠ରԠ͍ͯ͠Δ • εΩʔϚࣗମͷόϦσʔγϣϯΛ͍ͯ͠ͳ͍ͷͰtypoͱ͔Λݟಀ͢ͱख ໭Γ͕ൃੜ͢Δ 


    →validatorͷdocker image͕͋ΔͷͰCIͰνΣοΫ͢ΔΑ͏ʹ͍ͨ͠
  27. ࠷ޙʹએ఻ We are hiring!!!

  28. We’re Hiring! ΤϯδχΞืूத https://info.studyplus.co.jp/recruit

  29. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠