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
230
PFNにある2つのKubernetes
ota42y
10
5.3k
ゼロから作るDeep Learning 2 3章 word2vec 3.1〜3.2
ota42y
1
450
How to use OpenAPI3 for API developer (RubyKaigi 2019)
ota42y
5
20k
How should we face with microservices (我々はマイクロサービスとどう向き合うべきか)
ota42y
20
4.7k
DeepLearningの本番環境にSageMakerを利用してる話
ota42y
1
6.2k
検索結果の良さを計測して定量的に改善していく
ota42y
3
2.4k
Flutterを広めるために技術同人誌を作った話
ota42y
1
1.6k
何も考えずにCIや継続的デリバリーしたら辛くなった話.pdf
ota42y
0
2.9k
Other Decks in Programming
See All in Programming
EventSourcingの理想と現実
wenas
6
2.1k
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
520
色々なIaCツールを実際に触って比較してみる
iriikeita
0
270
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
430
現場で役立つモデリング 超入門
masuda220
PRO
13
2.9k
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
hotwire_or_react
harunatsujita
8
4.1k
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
Honoの来た道とこれから
yusukebe
19
3k
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Navigating Team Friction
lara
183
14k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
107
49k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Writing Fast Ruby
sferik
626
61k
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ͷͲΕʹׂ͘ͷ͕Ұ൪͔ •
͔ͳΓޮՌతͳ໘͋ΔͷͰɺݟۃΊͱ֮ޛ