Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Q&A for How to use OpenAPI3 for API developer
Search
ota42y
May 15, 2019
Programming
0
2.5k
Q&A for How to use OpenAPI3 for API developer
AFTER RubyKaigi 2019での発表資料です
https://raksul.connpass.com/event/125165/
ota42y
May 15, 2019
Tweet
Share
More Decks by ota42y
See All by ota42y
バックログを導入し やっぱやめた話
ota42y
0
250
PFNにある2つのKubernetes
ota42y
10
5.4k
ゼロから作るDeep Learning 2 3章 word2vec 3.1〜3.2
ota42y
1
470
How to use OpenAPI3 for API developer (RubyKaigi 2019)
ota42y
5
21k
How should we face with microservices (我々はマイクロサービスとどう向き合うべきか)
ota42y
20
4.7k
DeepLearningの本番環境にSageMakerを利用してる話
ota42y
1
6.3k
検索結果の良さを計測して定量的に改善していく
ota42y
3
2.4k
Flutterを広めるために技術同人誌を作った話
ota42y
1
1.6k
何も考えずにCIや継続的デリバリーしたら辛くなった話.pdf
ota42y
0
2.9k
Other Decks in Programming
See All in Programming
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
140
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
130
선언형 UI에서의 상태관리
l2hyunwoo
0
140
快速入門可觀測性
blueswen
0
330
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
CSC509 Lecture 14
javiergs
PRO
0
140
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Navigating Team Friction
lara
183
15k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Typedesign – Prime Four
hannesfritz
40
2.4k
Thoughts on Productivity
jonyablonski
67
4.4k
Automating Front-end Workflow
addyosmani
1366
200k
Building Applications with DynamoDB
mza
91
6.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
The Invisible Side of Design
smashingmag
298
50k
Unsuck your backbone
ammeep
669
57k
Transcript
Q&A for How to use OpenAPI3 for API developer
AFTER RubyKaigi 2019 ota42y
about me
about me • @ota42y • ϔϧεςοΫΧϯύχʔͷαʔόαΠυΤϯδχΞ • ϚΠΫϩαʔϏεΑΖͣຊΈ͍ͨͳͷΛग़ͯ͠·͢ • ిࢠ൛͋ΔΑ(ƅ㱼ƅ)oኯƅ
• https://ota42y.booth.pm/items/1316740 • https://ota42y.booth.pm/items/1316130
Today’s topic • OpenAPI3ͷൃදͷ͓͞Β͍ • دͤΒΕ࣭ͨͱճ
OpenAPI3ͷൃදͷ͓͞Β͍
OpenAPI3 • ϓϩάϥϛϯάݴޠʹґଘ͠ͳ͍REST APIͷͨΊͷఆٛ • ͔ͭͯSwaggerͱݺΕ͍ͯͯɺͦΕͷ࣍όʔδϣϯ • ϚγʔϯϦʔμϒϧͳYAML/JSONͷϧʔϧͰɺυΩϡϝϯτ ੜόϦσʔγϣϯɺϞοΫαʔόϥΠϒϥϦੜͳͲԠ ༻ଟ
https://www.openapis.org/
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
ਓͷखʹΑΔԹ͔Έͷ͋Δఆ่ٛΕΔ • ࣮ͱఆ͕ٛҰக͍ͯ͠Δͷ͕େલఏ • ͣΕΔͱఆ͕ٛ৴པͰ͖ͳ͘ͳΔ • ྗͰҰகͤ͞Δͷແཧ
OpenAPI 3ʹΑΔࣗಈνΣοΫ • OpenAPI 3ϚγʔϯϦʔμϒϧͳఆٛ • ఆٛͱͷζϨΛϓϩάϥϜͰνΣοΫͰ͖Δ • committee •
rackͰrequest/response͕ఆٛͲ͓Γ͔ΛνΣοΫ͢Δgem • ఆٛ௨Γͷ࣮Ͱ͋ΔͱอূͰ͖Δ
Example API get "/apps" do content_type :json # page should
be Integer page = params["page"] [page, (page*10)].map(&:to_s).to_json end
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
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
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
ͦͷଞͷOpenAPI 3ͷ׆༻ • OpenAPI Generator • client libraryΛੜ͢Δπʔϧ • Swagger
Editor • OpenAPI 3ͷఆٛΛॻ͘ΠϯλϥΫςΟϒͳΤσΟλ • ࣮ࡍʹαʔόʹϦΫΤετΛΕΔυΩϡϝϯτΛॻ͚Δ • ଞʹProtocol BuffersΛੜͨ͠Γͱ͔৭ʑ…ৄ͘͠ https://openapi.tools/
Q&A for How to use OpenAPI 3 for API
developer
Q.committeeຊ൪ڥͰͬͯΔ͔? • Yes • committeeܕͷύϥϝʔλΛม͢Δػೳ͕͋ΔͷͰrequestͰͬͯΔ (datetimeͳstringΛDateTimeΫϥεʹͨ͠ΓɺGETͩͱͯ͢stringʹͳΔͷ ͰIntegerʹ͢Δͱ͔) • ϦΫΤετʹ͔͠దԠ͞Εͳ͍ͨΊɺϨεϙϯεͷόϦσʔγϣϯͯ͠ͳ͍ •
։ൃڥʹ͓͍ͯrequset/responseͷόϦσʔγϣϯΛೖΕ͍ͯΔ
Q.committee ΛೖΕͨ͜ͱʹΑΔӨڹ? • ϕϯνϚʔΫΛऔΓ·ͨ͠ • https://gist.github.com/ota42y/1a5fb27e31aa5868af307fd66f52878b • ύϥϝʔλ͕1ݸͷখن • ύϥϝʔλ͕260ݸͷதن
• ύϥϝʔλ͕2600ݸͷେن • ͦΕͧΕcommitteeͷON/OFFͰ10000ճܭଌ
committee ΛೖΕͨ͜ͱʹΑΔӨڹ? • responseʹؔͯ͠νΣοΫͯ͠ͳ͍ • ࣮ͱͯ͠ڞ௨ͳͷͰ΄΅มΘΒͳ͍ͣ • ڥRuby 2.6.3ɺMac Book
Pro, Core i5 2.7GHz
ίʔυ • https://gist.github.com/ota42y/ 1a5fb27e31aa5868af307fd66f52878b
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
தن • Validate 260 objects by 0.16 milliseconds per request
• But the difference is still small VTFS TZTUFN UPUBM SFBM /PU6TF 6TF
େن • Validate 2600 objects by 0.74 milliseconds per request
• It’s very small difference VTFS TZTUFN UPUBM SFBM /PU6TF 6TF
A.ϕϯνϚʔΫ݁Ռ • தنύϥϝʔλͰେ͖ࠩ͘ग़ͯͳ͍ • Mac Book ProڥͰ0.1ʙ2ms • Կແ͍࣌ͱͷࠩখ͍͞ •
࣮ࡍͷαʔόͰ΄΅Өڹແ͍ͣ • requestʹ100ύϥϝʔλΔͷ͔ͳΓେ͖͍͜ͱΛߟ͑Δͱɺ΄΅ແࢹ Ͱ͖Δͣ
Q. OpenAPI 3.0.1ͩͱಈ͔ͳ͍Μ͚ͩͲ • ͖ͬ͞͠·ͨ͠
Q. OpenAPI 3.0.1ͩͱಈ͔ͳ͍Μ͚ͩͲ • ϦϦʔεͯ͋͠Γ·͢㱬(ɾ8ɾ)⊃
ຊ൪͜͜Ͱ࣌ؒΕ
Q.GraphQL / gRPC ͱൺͯͲ͏Α • ͲΕ͕͍͍͔ϝϯόʔΫϥΠΞϯτଆͷ࣮ɺݴޠʹΑΔ • GraphQLಋೖ͚ͯͨ͠ͲΞϓϦଆͷ࣮ઓུʹ߹Θͣʹ׆༻Ͱ͖ͣɺ݁ ہࣺͯͨ •
gRPCRailsͩͱݱঢ়·ͩਏ͍ͱ͍͏ࣄ࣮ • Go ͱ͔ͳΒ༗ྗͳબࢶ • ΫοΫύου͕ؤுͬͯΔ
ࠓͷੈքRESTʹ࠷దԽ͞ΕͯΔ • ΤίγεςϜͱ͔ݟREST͕ੌ͍ • ͦͦRailsRESTͱੑ͕͍͍ • GraphQL/gRPCΛೖΕΔͷ͍ͩͿΤωϧΪʔ͕ඞཁ • ಉ͡࿑ྗΛRESTͱGraphQL/gRPCͷͲΕʹׂ͘ͷ͕Ұ൪͔ •
͔ͳΓޮՌతͳ໘͋ΔͷͰɺݟۃΊͱ֮ޛ