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

OpenAPI Generator Meetup #1

OpenAPI Generator Meetup #1

OpenAPI Generator Meetup #1 で発表した資料です!
https://openapi-generator-meetup.connpass.com/event/168187/

Akihito Nakano

March 10, 2020
Tweet

More Decks by Akihito Nakano

Other Decks in Technology

Transcript

  1. த໺ڿਓΞεΫϧגࣜձࣾ
    0QFO"1*(FOFSBUPS.FFUVQ
    0QFO"1*(FOFSBUPS.FFUVQ
    ʙਓྨ૯ίϯτϦϏϡʔλԽܭըʙ

    View full-size slide

  2. 8FCΞϓϦέʔγϣϯΤϯδχΞ
    த໺ڿਓ
    IUUQTBDLJOUPTIHJUIVCJPBCPVU
    BDLJOUPTI
    /","/0@"LJIJUP

    View full-size slide

  3. 044׆ಈ
    w0QFO"1*(FOFSBUPS
    wIUUQTHJUIVCDPN0QFO"1*5PPMTPQFOBQJHFOFSBUPS
    w(BOFTIB Ψωʔγϟ

    wIUUQTHJUIVCDPNBDLJOUPTIHBOFTIB
    w4OJEFM εφΠσϧ

    wIUUQTHJUIVCDPNBDLJOUPTITOJEFM

    View full-size slide


  4. OpenAPI Generator Meetup #1
    https://openapi-generator-meetup.connpass.com/event/168187/

    View full-size slide

  5. ໨࣍
    ͍ΖΜͳ಺༰͕ࠞͬͨ͟
    ࡶଟͳൃදͰ͢
    w Θͨ͠ͷ0QFO"1*(FOFSBUPS׆༻ঢ়گ
    w 0QFO"1*υΩϡϝϯτΛ࢖ͬͯࠓޙ΍Γ͍ͨ͜ͱ
    w 4QSJOH$MPVE$POUSBDU0QFO"1*
    w 0QFO"1*(FOFSBUPSͷ࠷ۙͷτϐοΫΛ͝঺հ
    w υΩϡϝϯταΠτ͕Ξοϓσʔτ
    w )BOEMFCBSTʹରԠ
    w ΧελϜςϯϓϨʔτΤϯδϯʹରԠ
    w PQFOBQJTUZMFWBMJEBUPSϦϙδτϦ
    w ,VCFSOBUFTͷ3&45"1*ΫϥΠΞϯτੜ੒πʔϧͱͯ͠࠾༻͕ਐΜͰ͍Δ
    w ͓ΘΓʹ

    View full-size slide

  6. Θͨ͠ͷ
    OpenAPI Generator׆༻ঢ়گ

    View full-size slide

  7. ͱ͋ΔγεςϜ
    ϑϩϯτ
    αʔό
    ഑ૹ ঎඼
    ސ٬
    ஫จ
    "1*
    ,PUMJO
    4QSJOH#PPU
    4QSJOH8FC'MVY
    ,PUMJO+BWB
    4QSJOH#PPU
    4QSJOH.7$
    0QFO"1*
    "1*࢓༷
    ͦͷଞ

    View full-size slide

  8. ഑ૹ ঎඼
    ސ٬
    ஫จ
    ,PUMJO
    4QSJOH#PPU
    4QSJOH8FC'MVY
    ,PUMJO+BWB
    4QSJOH#PPU
    4QSJOH.7$
    "1*࢓༷
    ͦͷଞ
    "1*
    ͱ͋ΔγεςϜ0QFO"1*(FOFSBUPSͷ׆༻ঢ়گ
    ϑϩϯτ
    αʔό
    ϑϩϯταʔόͰ࢖͏
    ϞσϧΫϥεͷੜ੒͚ͩ
    0QFO"1*

    View full-size slide

  9. ໨࣍
    w Θͨ͠ͷ0QFO"1*(FOFSBUPS׆༻ঢ়گ
    w 0QFO"1*υΩϡϝϯτΛ࢖ͬͯࠓޙ΍Γ͍ͨ͜ͱ
    w 4QSJOH$MPVE$POUSBDU0QFO"1*
    w 0QFO"1*(FOFSBUPSͷ࠷ۙͷτϐοΫΛ͝঺հ
    w υΩϡϝϯταΠτ͕Ξοϓσʔτ
    w )BOEMFCBSTʹରԠ
    w ΧελϜςϯϓϨʔτΤϯδϯʹରԠ
    w PQFOBQJTUZMFWBMJEBUPSϦϙδτϦ
    w ,VCFSOBUFTͷ3&45"1*ΫϥΠΞϯτੜ੒πʔϧͱͯ͠࠾༻͕ਐΜͰ͍Δ
    w ͓ΘΓʹ
    Ұ୴0QFO"1*(FOFSBUPS͔Β
    ࿩͕୤ઢ͠·͢

    View full-size slide

  10. APIͷςετΛ
    ࣗಈੜ੒͍ͨ͠

    View full-size slide

  11. 8%#1SFTTWPMεΩʔϚۦಈ8FC"1*։ൃ
    IUUQTHJIZPKQNBHB[JOFXEQSFTTBSDIJWFWPM
    ୈষ0QFO"1*ʹΑΔεΩʔϚۦಈ։ൃ
    ʮεΩʔϚΛ༻͍ͯ࢓༷ͱ࣮૷ͷҰகΛࣗಈςετ͢Δʯ
    3VCZPO3BJMTͰ࣮૷ͨ͠"1*αʔόͷϨεϙϯε͕ɺ
    0QFO"1*υΩϡϝϯτͱဃ཭͍ͯ͠ͳ͍͔Λࣗಈςετ͢Δ
    ࣮૷Λ঺հ͍ͯ͠Δɻ
    ར༻͞Ε͍ͯΔϥΠϒϥϦ

    34QFD
    PBT@QBSTFS
    KTPO@TDIFNB
    $PNNJUUFF

    View full-size slide

  12. Spring Cloud Contract
    (SCC)
    ͦ͜Ͱ…
    ʹ໨Λ͚ͭ·ͨ͠

    View full-size slide

  13. 4QSJOH$MPVE$POUSBDU 4$$

    w4QSJOH$MPVE$POUSBDU͸$%$ ˞
    ͷ࣮ફΛαϙʔτ͢Δπʔϧ
    w"1*ʹظ଴͢ΔڍಈΛl$POUSBDUzʹهड़͢Δ
    wˠʮϦΫΤετ999Λ౤͛ͨΒɺϨεϙϯε:::Λฦ͢ʯ
    wهड़ͨ͠$POUSBDU͔Βελϒαʔό΍ςετΛࣗಈੜ੒Ͱ͖Δ
    w ˞
    $%$$POTVNFS%SJWFO$POUSBDUTEFWFMPQNFOU
    w IUUQXXXTFSWJDFEFTJHOQBUUFSOTDPN8FC4FSWJDF&WPMVUJPO$POTVNFS%SJWFO$POUSBDUT
    w "1*ར༻ऀ͕ظ଴͢ΔڍಈΛυΩϡϝϯτԽ͢Δ $POUSBDU

    w "1*ར༻ऀఏڙऀͷ૒ํ͕$POUSBDUΛ΋ͱʹςετΛߦ͏͜ͱͰ඼࣭Λอͪͳ͕ΒχʔζΛຬͨ
    ͢։ൃΛߦ͏
    IUUQTHJUIVCDPNTQSJOHDMPVETQSJOHDMPVEDPOUSBDU

    View full-size slide

  14. 4QSJOH$MPVE$POUSBDU 4$$

    $POUSBDU (SPPWZ%4-
    ࣗಈੜ੒͞ΕΔςετίʔυ
    "1*ͷ࢓༷Λهड़ͨ͠$POUSBDU͔ΒςετίʔυΛࣗಈੜ੒ͨ͠ྫ

    View full-size slide

  15. Spring Cloud Contract OpenAPI
    ͜Ε͸͏·͘࢖͑ͦ͏ɺͱ͍͏͜ͱͰ
    Λ։ൃதͰ͢

    View full-size slide

  16. 4QSJOH$MPVE$POUSBDU0QFO"1* ಈ࡞Πϝʔδ

    0QFO"1*υΩϡϝϯτ
    4QSJOH$MPVE$POUSBDU0QFO"1*
    0QFO"1*υΩϡϝϯτˠ$POUSBDUͷΦϒδΣΫτʹม׵
    ςετίʔυ
    ೖྗ

    ग़ྗ

    View full-size slide

  17. 4QSJOH$MPVE$POUSBDU0QFO"1*
    w0QFO"1*υΩϡϝϯτͷఆ͔ٛΒ4QSJOH#PPUͷςετίʔυΛࣗಈੜ੒͢Δ
    (SBEMF.BWFOϓϥάΠϯ
    w಺෦Ͱɺ0QFO"1*υΩϡϝϯτ͔Β$POUSBDUʹม׵͍ͯ͠Δ
    wઈࢍ։ൃதͰɺ·ͩ·࣮ͩ༻·Ͱ͸ԕ͍ʜ
    IUUQTHJUIVCDPNBDLJOUPTITQSJOHDMPVEDPOUSBDUPQFOBQJ
    IUUQTHJUIVCDPNBDLJOUPTITQSJOHDMPVEDPOUSBDUPQFOBQJTBNQMF
    * αϯϓϧίʔυ
    * ϦϙδτϦ

    View full-size slide

  18. ໨࣍
    w Θͨ͠ͷ0QFO"1*(FOFSBUPS׆༻ঢ়گ
    w 0QFO"1*υΩϡϝϯτΛ࢖ͬͯࠓޙ΍Γ͍ͨ͜ͱ
    w 4QSJOH$MPVE$POUSBDU0QFO"1*
    w 0QFO"1*(FOFSBUPSͷ࠷ۙͷτϐοΫΛ͝঺հ
    w υΩϡϝϯταΠτ͕Ξοϓσʔτ
    w )BOEMFCBSTʹରԠ
    w ΧελϜςϯϓϨʔτΤϯδϯʹରԠ
    w PQFOBQJTUZMFWBMJEBUPSϦϙδτϦ
    w ,VCFSOBUFTͷ3&45"1*ΫϥΠΞϯτੜ੒πʔϧͱͯ͠࠾༻͕ਐΜͰ͍Δ
    w ͓ΘΓʹ
    0QFO"1*(FOFSBUPSʹؔ܎͢Δ
    ׂͱ࠷ۙͷτϐοΫΛ
    େখ͍͔ͭ͘͝঺հ͠·͢

    View full-size slide

  19. υΩϡϝϯταΠτ͕Ξοϓσʔτ IUUQTPQFOBQJHFOFSBUPSUFDI
    μʔΫϞʔυ
    αΠτ಺ݕࡧ

    View full-size slide

  20. )BOEMFCBSTʹରԠ FYQFSJNFOUBM

    w W͔Βɺैདྷͷ.VTUBDIFʹՃ͑ͯɺ)BOEMFCBSTʹࢼݧతʹରԠ
    w F FOHJOF
    ΦϓγϣϯͰςϯϓϨʔτΤϯδϯΛࢦఆ
    w ·ͩ૊ΈࠐΈͷςϯϓϨʔτ͸.VTUBDIFͰॻ͔Ε͍ͯΔ
    w ͳͷͰࠓͷॴɺ)BOEMFCBSTͰςϯϓϨʔτΛॻ͖͍ͨ৔߹͸ɺࣗલͰδΣωϨʔλΫϥε
    9YY$PEFHFOΫϥε
    Λ࣮૷͢Δඞཁ͋Γ
    w δΣωϨʔλΫϥε࣮૷ʹ͍ͭͯͷυΩϡϝϯτ
    w IUUQTPQFOBQJHFOFSBUPSUFDIEPDTDVTUPNJ[BUJPODVTUPNHFOFSBUPSBOEUFNQMBUF
    $ openapi-generator \
    generate \
    -e handlebars \
    -t {Handlebarsͷه๏Ͱॻ͔ΕͨςϯϓϨʔτ}
    ɹ {লུ}

    View full-size slide

  21. ΧελϜςϯϓϨʔτΤϯδϯʹରԠ FYQFSJNFOUBM

    w W͔ΒࢼݧతʹରԠ
    w ྫ1FCCMF&3#4NBSUZͰςϯϓϨʔτΛॻ͖͍ͨ৔߹
    w 5FNQMBUF&OHJOF"EBQUFSΠϯλʔϑΣʔεΛ࣮૷͢Δ
    w ΧελϜςϯϓϨʔτΤϯδϯ͍ͭͯͷυΩϡϝϯτ
    w IUUQTPQFOBQJHFOFSBUPSUFDIEPDTUFNQMBUJOHDVTUPNFOHJOFT
    # PebbleςϯϓϨʔτΤϯδϯʹରԠͨ͠ΞμϓλΛclasspathʹೖΕ࣮ͯߦ͢Δ
    $ java -cp \
    /path/to/pebble-adapter.jar:modules/openapi-generator-cli/target/openapi-generator-cli.jar \
    generate \
    -e pebble \
    -g php \
    {লུ}

    View full-size slide

  22. 0QFO"1*5PPMTPQFOBQJTUZMFWBMJEBUPS
    w 0QFO"1*υΩϡϝϯτͷ-JOUπʔϧ
    w νʔϜ΍ϓϩμΫτಠࣗͷهड़ϧʔϧΛܾΊͯɺݕূΛࣗಈԽͰ͖Δ
    w ྫPQFSBUJPO*E͸ඞͣࢦఆ͢Δɺ.PEFMʹ͸ඞͣFYBNQMFTΛఆٛ͢ΔɺϓϩύςΟ໊͸ΩϟϝϧέʔεͰ
    $ java \
    -jar /path/to/openapi-style-validator-cli.jar \
    -s openapi.yaml \ # ର৅ͷOpenAPIυΩϡϝϯτ
    -o options.json # όϦσʔγϣϯͷϧʔϧΛఆٛͨ͠JSONϑΝΠϧ
    *ERROR* in Model 'Pet', property 'status', field 'example' -> This field
    should be present and not empty
    $ echo $status
    1
    IUUQTHJUIVCDPN0QFO"1*5PPMTPQFOBQJTUZMFWBMJEBUPS
    FYBNQMF͕
    ະఆٛʹͳ͍ͬͯΔͷΛ
    ࢦఠͯ͘͠Ε͍ͯΔ

    View full-size slide

  23. ,VCFSOBUFTͷ3&45"1*ΫϥΠΞϯτੜ੒πʔϧͱͯ͠࠾༻
    w 4XBHHFS$PEFHFO͕࢖ΘΕ͍͕ͯͨɺ4XBHHFS$PEFHFO
    ͷ։ൃ͕͋·Γ׆ൃͰ͸ͳ͍ͨΊʹɺੜ੒ޙͷίʔυʹಠࣗ
    ʹύονΛ౰ͯͯӡ༻͍ͯͯ͠ϝϯςφϯε͕ਏ͍ঢ়ଶͩͬ
    ͨ
    w ҠߦࡁΈ
    w $ɺ)BTLFMMɺ+BWBɺ1FSMɺ1ZUIPOɺ5ZQF4DSJQU
    w Ҡߦத
    w (Pɺ3VCZ
    IUUQTHJUIVCDPNLVCFSOFUFTDMJFOUHFOJTTVFT

    View full-size slide

  24. ׆ൃͳ։ൃίϛϡχςΟ
    IUUQTTUBSTQS[FNFLOPXBLDPN
    (PPHMFτϨϯυ
    TXBHHFSDPEFHFO PQFOBQJHFOFSBUPS
    (JU)VCελʔ
    IUUQTXXXTMJEFTIBSFOFUUFDICMPHZBIPPTXBHHFSPQFOBQJTQFDJpDBUJPOBQJ
    4XBHHFSͰ͸ͳ͍0QFO"1*4QFDJpDBUJPOʹΑΔ"1*αʔόʔ։ൃ
    IUUQTPQFOBQJHFOFSBUPSUFDIVTFST
    ϢʔβʔاۀϓϩδΣΫτ
    IUUQTHJUIVCDPN0QFO"1*5PPMTPQFOBQJHFOFSBUPS
    ϒϩάهࣄɺൃදεϥΠυ

    View full-size slide

  25. ҰํͰʜɺ
    w ͨͱ͑ίΞνʔϜͷϝϯόʔͰ΋ɺશ͘஌Βͳ͍ݴޠͷϝϯςφϯε͸ݫ͍͠ʜ
    w 0QFO"1*(FOFSBUPS͕αϙʔτ͍ͯ͠Δݴޠ͸Ҏ্
    ʢ଺ཹͯ͠͠·͏JTTVFʣ
    w ʮ0QFO"1*(FOFSBUPS͸ίί͕Πέͯͳ͍ΜͩΑͳ͊ʯ
    w ʮͪΐͬͱ044ͷ։ൃ΍ͬͯΈ͍ͨͳʯ
    w ʮϓϧϦΫग़͢ͷ͸ϋʔυϧߴ͍ͳ͊ɺ͍ͯ͏͔ӳޠͩ͠ʜʯ
    ؾܰʹ͓੠ֻ͚͍ͩ͘͞ʂαϙʔτ͠·͢✨

    View full-size slide

  26. ࢲͨͪͱҰॹʹ։ൃ͠·ͤΜ͔

    View full-size slide