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
240
PFNにある2つのKubernetes
ota42y
10
5.4k
ゼロから作るDeep Learning 2 3章 word2vec 3.1〜3.2
ota42y
1
460
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
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Quine, Polyglot, 良いコード
qnighy
4
640
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
1
110
Macとオーディオ再生 2024/11/02
yusukeito
0
370
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Remix on Hono on Cloudflare Workers
yusukebe
1
280
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Making Projects Easy
brettharned
115
5.9k
Documentation Writing (for coders)
carmenintech
65
4.4k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Embracing the Ebb and Flow
colly
84
4.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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ͷͲΕʹׂ͘ͷ͕Ұ൪͔ •
͔ͳΓޮՌతͳ໘͋ΔͷͰɺݟۃΊͱ֮ޛ