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
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
A designer walks into a library…
pauljervisheath
204
24k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Scaling GitHub
holman
458
140k
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ͷͲΕʹׂ͘ͷ͕Ұ൪͔ •
͔ͳΓޮՌతͳ໘͋ΔͷͰɺݟۃΊͱ֮ޛ