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
快速入門可觀測性
blueswen
0
370
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
910
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
php-conference-japan-2024
tasuku43
0
310
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
440
useSyncExternalStoreを使いまくる
ssssota
6
1.1k
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.1k
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
790
ドメインイベント増えすぎ問題
h0r15h0
2
330
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
Featured
See All Featured
Site-Speed That Sticks
csswizardry
2
190
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Code Reviewing Like a Champion
maltzj
520
39k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Documentation Writing (for coders)
carmenintech
66
4.5k
Adopting Sorbet at Scale
ufuk
73
9.1k
What's in a price? How to price your products and services
michaelherold
243
12k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
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ͷͲΕʹׂ͘ͷ͕Ұ൪͔ •
͔ͳΓޮՌతͳ໘͋ΔͷͰɺݟۃΊͱ֮ޛ