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. ໨࣍ ͍ΖΜͳ಺༰͕ࠞͬͨ͟ ࡶଟͳൃදͰ͢ 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 ͓ΘΓʹ
  2. ͱ͋ΔγεςϜ ϑϩϯτ αʔό ഑ૹ ঎඼ ސ٬ ஫จ "1* ,PUMJO 4QSJOH#PPU

    4QSJOH8FC'MVY ,PUMJO+BWB 4QSJOH#PPU 4QSJOH.7$ 0QFO"1* "1*࢓༷ ͦͷଞ
  3. ഑ૹ ঎඼ ސ٬ ஫จ ,PUMJO 4QSJOH#PPU 4QSJOH8FC'MVY ,PUMJO+BWB 4QSJOH#PPU 4QSJOH.7$

    "1*࢓༷ ͦͷଞ "1* ͱ͋ΔγεςϜ0QFO"1*(FOFSBUPSͷ׆༻ঢ়گ ϑϩϯτ αʔό ϑϩϯταʔόͰ࢖͏ ϞσϧΫϥεͷੜ੒͚ͩ 0QFO"1*
  4. ໨࣍ 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͔Β ࿩͕୤ઢ͠·͢
  5. 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
  6. ໨࣍ 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ʹؔ܎͢Δ ׂͱ࠷ۙͷτϐοΫΛ େখ͍͔ͭ͘͝঺հ͠·͢
  7. )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ͷه๏Ͱॻ͔ΕͨςϯϓϨʔτ} ɹ {লུ}
  8. ΧελϜςϯϓϨʔτΤϯδϯʹରԠ 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 \ {লུ}
  9. 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͕ ະఆٛʹͳ͍ͬͯΔͷΛ ࢦఠͯ͘͠Ε͍ͯΔ