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

Q&A for 
How to use OpenAPI3 for API developer

ota42y
May 15, 2019

Q&A for 
How to use OpenAPI3 for API developer

AFTER RubyKaigi 2019での発表資料です
https://raksul.connpass.com/event/125165/

ota42y

May 15, 2019
Tweet

More Decks by ota42y

Other Decks in Programming

Transcript

  1. APIͷఆٛͷॏཁੑ • େྔʹAPI͕͋Δ৔߹ɺυΩϡϝϯτ͕ॏཁʹͳΔ
 (ϚΠΫϩαʔϏεͩͱ1000ݸҎ্API͕͋ͬͨΓ͢Δ) • εΩʔϚϑΝʔετ։ൃ͢Δ৔߹ɺΠϯλϑΣʔεΛ͖ͬͪΓ ఆٛ͢Δඞཁ͕͋Δ • εΩʔϚϑΝʔετ։ൃʹ͍ͭͯৄ͘͠͸ͬͪ͜ Reference:

    RubyKaigi 2017 API Development in 2017 https://www.youtube.com/watch?v=a28jJ62ZfZM Rails Developers Meetup 2019: 
 https://speakerdeck.com/aeroastro/rails-meets-protocol-buffers-for-schema-first-development
  2. OpenAPI 3ʹΑΔࣗಈνΣοΫ • OpenAPI 3͸ϚγʔϯϦʔμϒϧͳఆٛ • ఆٛͱͷζϨΛϓϩάϥϜͰνΣοΫͰ͖Δ • committee •

    rack૚Ͱrequest/response͕ఆٛͲ͓Γ͔ΛνΣοΫ͢Δgem • ఆٛ௨Γͷ࣮૷Ͱ͋ΔͱอূͰ͖Δ
  3. Example API get "/apps" do content_type :json # page should

    be Integer page = params["page"] [page, (page*10)].map(&:to_s).to_json end
  4. Example API openapi: 3.0.0 info: title: Sample API version: 0.1.0

    paths: "/apps": get: parameters: - name: page in: query required: true schema: type: integer responses: '200': description: example content: 'application/json': schema: type: array items: type: string
  5. Example API openapi: 3.0.0 info: title: Sample API version: 0.1.0

    paths: "/apps": get: parameters: - name: page in: query required: true schema: type: integer responses: '200': description: example content: 'application/json': schema: type: array items: type: string
  6. Example API openapi: 3.0.0 info: title: Sample API version: 0.1.0

    paths: "/apps": get: parameters: - name: page in: query required: true schema: type: integer responses: '200': description: example content: 'application/json': schema: type: array items: type: string
  7. ͦͷଞͷOpenAPI 3ͷ׆༻ • OpenAPI Generator • client libraryΛੜ੒͢Δπʔϧ • Swagger

    Editor • OpenAPI 3ͷఆٛΛॻ͘ΠϯλϥΫςΟϒͳΤσΟλ • ࣮ࡍʹαʔόʹϦΫΤετΛ஗ΕΔυΩϡϝϯτΛॻ͚Δ • ଞʹ΋Protocol BuffersΛੜ੒ͨ͠Γͱ͔৭ʑ…ৄ͘͠͸ https://openapi.tools/ ΁
  8.  VTFS TZTUFN UPUBM SFBM /PU6TF    

    6TF     খن໛ • 10000 times request time so 0.08 ms per request • So the committee doesn’t take 0.1 millisecond • The difference is very small
  9. தن໛ • Validate 260 objects by 0.16 milliseconds per request

    • But the difference is still small  VTFS TZTUFN UPUBM SFBM /PU6TF     6TF    
  10. େن໛ • Validate 2600 objects by 0.74 milliseconds per request

    • It’s very small difference  VTFS TZTUFN UPUBM SFBM /PU6TF     6TF    
  11. A.ϕϯνϚʔΫ݁Ռ • தن໛ύϥϝʔλͰ΋େ͖ࠩ͘͸ग़ͯͳ͍ • Mac Book Pro؀ڥͰ0.1ʙ2ms • Կ΋ແ͍࣌ͱͷࠩ͸খ͍͞ •

    ࣮ࡍͷαʔόͰ΋΄΅Өڹ͸ແ͍͸ͣ • requestʹ100ύϥϝʔλ৐Δͷ͸͔ͳΓେ͖͍͜ͱΛߟ͑Δͱɺ΄΅ແࢹ Ͱ͖Δ͸ͣ