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

Proto definition file (.proto file) で JSON API の schema を管理する

2b4f9f20b554d4c77c46fe6a9930d6fe?s=47 Nao Minami
January 29, 2019

Proto definition file (.proto file) で JSON API の schema を管理する

Meguro.rb#23 で「Proto definition file (.proto file) で JSON API の schema を管理する」という発表をしました!
https://megurorb.connpass.com/event/115497/

2b4f9f20b554d4c77c46fe6a9930d6fe?s=128

Nao Minami

January 29, 2019
Tweet

Transcript

  1. ©2018 Wantedly, Inc. Proto definition file (.proto file) Ͱ JSON

    API ͷ schema Λ؅ཧ͢Δ 29.Jan.2019 - Nao Minami (@south37) Wantedly, Inc. Meguro.rb#23
  2. ©2018 Wantedly, Inc. ࣗݾ঺հ

  3. ©2018 Wantedly, Inc. /BP.JOBNJ *OGSBTUSVDUVSF&OHJOFFS 8BOUFEMZ *OD (JU)VCTPVUI 5XJUUFSTPVUI 

    43&ͱͯ͠ͷ໾ׂʢαʔϏεͷ৴པੑʹ੹೚ʣ  ։ൃج൫ͱͯ͠ͷ໾ׂʢΤϯδχΞͷੜ࢈ੑʹ੹೚ʣ
  4. ©2018 Wantedly, Inc.  എܠ.JDSPTFSWJDFT"SDIJUFDUVSFͷ౷߹ٕज़ͱ ͯ͠ԿΛબͿ΂͖͔  ఏҊQSPUPpMFͰ3BJMT੡+40/"1*ͷ TDIFNBΛ؅ཧ͢Δ 

    ·ͱΊ "HFOEB
  5. ©2018 Wantedly, Inc.  എܠ.JDSPTFSWJDFT"SDIJUFDUVSFͷ౷߹ٕज़ͱ ͯ͠ԿΛબͿ΂͖͔  ఏҊQSPUPpMFͰ3BJMT੡+40/"1*ͷ TDIFNBΛ؅ཧ͢Δ 

    ·ͱΊ "HFOEB
  6. ©2018 Wantedly, Inc. .JDSPTFSWJDFT

  7. ©2018 Wantedly, Inc. w .JDSPTFSWJDFTͷϝϦοτ w ٕज़ҟ࣭ੑ w εέʔϦϯά w

    σϓϩΠ༰қੑ w ૊৫໘ͷҰக w FUD .JDSPTFSWJDFT ग़యʰϚΠΫϩαʔϏεΞʔΩςΫνϟʱΦϥΠϦʔɾδϟύϯ
  8. ©2018 Wantedly, Inc. .JDSPTFSWJDFT͸ Ͳ͏౷߹͢Δ΂͖͔ʁ

  9. ©2018 Wantedly, Inc. w .JDSPTFSWJDFTͷཧ૝తͳ౷߹ٕज़ w ഁյతมߋΛճආͰ͖Δ w "1*͕ٕज़ඇґଘ w

    ίϯγϡʔϚʹͱͬͯ୯७ͳαʔϏε w ಺෦ͷ࣮૷ৄࡉΛӅ͢ .JDSPTFSWJDFTͷ౷߹ٕज़ ग़యʰϚΠΫϩαʔϏεΞʔΩςΫνϟʱΦϥΠϦʔɾδϟύϯ
  10. ©2018 Wantedly, Inc.

  11. ©2018 Wantedly, Inc. w HSQDͷಛ௃ w 1SPUPDPM#V⒎FSpMF QSPUPpMF ʹΑΔ TDIFNB؅ཧ

    w CJOBSZGPSNBUͱTFSJBMJ[FEFTFSJBMJ[F ίʔυͷࣗಈੜ੒ w )551Λར༻ͨ͠ޮ཰తͳUSBOTQPSU HSQDͱ͸
  12. ©2018 Wantedly, Inc. w HSQDͷಛ௃ w 1SPUPDPM#V⒎FSpMF QSPUPpMF ʹΑΔ TDIFNB؅ཧ

    w CJOBSZGPSNBUͱTFSJBMJ[FEFTFSJBMJ[F ίʔυͷࣗಈੜ੒ w )551Λར༻ͨ͠ޮ཰తͳUSBOTQPSU HSQDͱ͸
  13. ©2018 Wantedly, Inc. ͨͩɺ༷ʑͳࣄ৘ͰHSQDಋೖ ʹࢸΒͳ͍έʔε͕͋Δɻɻɻ

  14. ©2018 Wantedly, Inc. HSQDΛ࢖Θͣͱ΋Կͱ͔ͳ Βͳ͍͔ʁ

  15. ©2018 Wantedly, Inc. w HSQDͷಛ௃ w 1SPUPDPM#V⒎FSpMF QSPUPpMF ʹΑΔ TDIFNB؅ཧ

    w CJOBSZGPSNBUͱTFSJBMJ[FEFTFSJBMJ[F ίʔυͷࣗಈੜ੒ w )551Λར༻ͨ͠ޮ཰తͳUSBOTQPSU HSQDͱ͸
  16. ©2018 Wantedly, Inc. QSPUPpMFͰ3BJMT੡+40/"1*ͷ TDIFNBΛ؅ཧ͢Δ࢓૊ΈΛ࡞ͬͨ

  17. ©2018 Wantedly, Inc.  എܠ.JDSPTFSWJDFT"SDIJUFDUVSFͷ౷߹ٕज़ͱ ͯ͠ԿΛબͿ΂͖͔  ఏҊQSPUPpMFͰ3BJMT੡+40/"1*ͷ TDIFNBΛ؅ཧ͢Δ 

    ·ͱΊ "HFOEB
  18. ©2018 Wantedly, Inc. 1SPUPEFGJOJUJPOGJMF QSPUPGJMF ͱ͸ message Person { string

    name = 1; int32 id = 2; string email = 3; } ࢀߟϦϯΫIUUQTEFWFMPQFSTHPPHMFDPNQSPUPDPMCV⒎FST
  19. ©2018 Wantedly, Inc.

  20. ©2018 Wantedly, Inc. QSPUPpMFͷ಺༰͸+40/ Λهड़Ͱ͖Δ

  21. ©2018 Wantedly, Inc. QSPUPGJMFͰ+40/Λهड़͢Δ message Person { string name =

    1; int32 id = 2; string email = 3; } { "name": "Taro", "id": 13, "email": "taro@example.com" } QSPUPpMF +40/
  22. ©2018 Wantedly, Inc. QSPUPpMF͔Βίʔυੜ੒Λߦ͏

  23. ©2018 Wantedly, Inc. w TFSWFSTJEFͷίʔυੜ੒ w DMJFOUTJEFͷίʔυੜ੒ QSPUPGJMF͔Βͷίʔυੜ੒

  24. ©2018 Wantedly, Inc. w TFSWFSTJEFͷίʔυੜ੒ w DMJFOUTJEFͷίʔυੜ੒ QSPUPGJMF͔Βͷίʔυੜ੒

  25. ©2018 Wantedly, Inc. message Person { string name = 1;

    int32 id = 2; string email = 3; } module PersonAttributes extend ActiveSupport::Concern included do attribute :name attribute :id attribute :email end end QSPUPpMF SVCZ QSPUPGJMF͔ΒTFSWFSTJEFͷίʔυੜ੒ w "DUJWF.PEFM4FSJBMJ[FSͷίʔυΛੜ੒
  26. ©2018 Wantedly, Inc. class PersonSerializer < ApplicationSerializer include PersonAttributes end

    QSPUPGJMF͔ΒTFSWFSTJEFͷίʔυੜ੒ w ੜ੒ͨ͠ίʔυΛTFSJBMJ[FS͔Βར༻ class PeopleController < ApplicationController def show @person = Person.find(params[:id]) render json: @person end end
  27. ©2018 Wantedly, Inc. $ curl 'http://localhost:3000/people/13' | jq . {

    "name": "Taro", "id": 13, "email": "taro@example.com" }
  28. ©2018 Wantedly, Inc. QSPUPpMFͰهड़ͨ͠ +40/ΛฦͤΔʂ

  29. ©2018 Wantedly, Inc. w TFSWFSTJEFͷίʔυੜ੒ w DMJFOUTJEFͷίʔυੜ੒ QSPUPGJMF͔Βͷίʔυੜ੒

  30. ©2018 Wantedly, Inc. message Person { string name = 1;

    int32 id = 2; string email = 3; } module PersonAttributes extend ActiveSupport::Concern included do attribute :name attribute :id attribute :email end end QSPUPpMF SVCZ QSPUPGJMF͔ΒDMJFOUTJEFͷίʔυੜ੒ w NBQQJOHDMBTTͷίʔυΛੜ੒ʢTFSWFSͱಉ͡
  31. ©2018 Wantedly, Inc. QSPUPGJMF͔ΒDMJFOUTJEFͷίʔυੜ੒ class Models class Person < Base

    include Attributes::PersonAttributes end end w ੜ੒ͨ͠ίʔυΛNBQQJOHDMBTT͔Βར༻ w .PEFMT#BTFͱͯ͠ABUUSJCVUFAΛղऍ͢Δ࣮૷Λ༻ҙ w +40/ΛQBSTFͯ͠ɺσʔλΛอ࣋ɻϝιουͱͯ͠pFMEͷ஋ΛऔΓग़ͤΔ
  32. ©2018 Wantedly, Inc. [1] pry(main)> person = PeopleClient.get(13) I, …

    -- request: GET http://localhost:3000/people/13 . . . => <Models::Person name: “Taro”, id: 13, email: “taro@example.com"> [2] pry(main)> personn.name => “Taro"
  33. ©2018 Wantedly, Inc. QSPUPpMFͰهड़ͨ͠ +40/ΛQBSTFग़དྷΔDMJFOUʂ

  34. ©2018 Wantedly, Inc. QSPUPpMFͰ+40/"1*ͷTDIFNBΛ؅ཧ͠ɺ ͞Βʹίʔυੜ੒΋࣮ݱͰ͖ͨʂ

  35. ©2018 Wantedly, Inc.  എܠ.JDSPTFSWJDFT"SDIJUFDUVSFͷ౷߹ٕज़ͱ ͯ͠ԿΛબͿ΂͖͔  ఏҊQSPUPpMFͰ3BJMT੡+40/"1*ͷ TDIFNBΛ؅ཧ͢Δ 

    ·ͱΊ "HFOEB
  36. ©2018 Wantedly, Inc. w .JDSPTFSWJDFT"SDIJUFDUVSFͷԸܙΛड͚Δ ͨΊʹɺཧ૝తͳ౷߹ٕज़Λ࢖͍͍ͨ w ͦͷҝʹɺQSPUPpMFΛར༻ͯ͠+40/"1*ͷ TDIFNBΛهड़͠ɺ͞ΒʹTFSWFSɺDMJFOU࣮૷ ͷίʔυੜ੒Λߦͳͬͨʂ

    w ͳ͓ɺ࣮૷͕΋͏গ͠མͪண͍ͨΒɺ࢓૊ΈΛ044ͱͯ͠ެ։͢Δ༧ఆͰ͢ʢࠓ͸·ͩ 044ʹͳͬͯ·ͤΜɻɻɻʣ ·ͱΊ