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
プライベートAPIのクライアントをいい感じにしたい / pepabo_ec_tech_mtg02
Search
Akihito Nakano
May 16, 2017
Programming
0
1.7k
プライベートAPIのクライアントをいい感じにしたい / pepabo_ec_tech_mtg02
2017/05/16 第2回 EC事業部 Tech MTG
Akihito Nakano
May 16, 2017
Tweet
Share
More Decks by Akihito Nakano
See All by Akihito Nakano
OpenAPI Generator Meetup #1
akihito_nakano
1
1.2k
Libraの現状と技術面をざっくりと / astudy20191114
akihito_nakano
4
1.1k
カート刷新プロジェクトにおけるOpenAPIを活用したコード自動生成の今と明日 / astudy20190419
akihito_nakano
2
570
平静を保ち、コードを生成せよ 〜 OpenAPI Generator誕生の背景と軌跡 〜 / gunmaweb34
akihito_nakano
24
54k
サーキットブレーカー 〜 有料契約店舗数 国内 No.1 ECサービスに神を宿す 〜 / pepabo_ec_tech_mtg01
akihito_nakano
1
3.9k
並行・並列処理のテストは難しい
akihito_nakano
2
4.3k
並列処理で消耗しているかたへ - Snidel のご紹介 -
akihito_nakano
4
3.4k
Other Decks in Programming
See All in Programming
Realtime API 入門
riofujimon
0
150
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
最新TCAキャッチアップ
0si43
0
190
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
CSC509 Lecture 13
javiergs
PRO
0
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Bash Introduction
62gerente
608
210k
It's Worth the Effort
3n
183
27k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
GitHub's CSS Performance
jonrohan
1030
460k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Transcript
தڿਓ(.01&1"#0JOD ୈճ&$ࣄۀ෦5FDI.5( ϓϥΠϕʔτ"1*ͷΫϥΠΞϯτΛ ͍͍ײ͡ʹ͍ͨ͠
8&#ΞϓϦέʔγϣϯΤϯδχΞ &$ࣄۀ෦Χϥʔϛʔγϣοϓάϧʔϓ தڿਓ ͖͋ͬʔ !/","/0@"LJIJUP ಛ߈ୂνʔϜ IUUQTBDLJOUPTIHJUIVCJP
࣍ wղܾ͍ͨ͜͠ͱ wཧ w࣮ݱ·Ͱͷϋʔυϧ wϨϏϡʔґཔ
ղܾ͍ͨ͜͠ͱ
ΧΦεԽ͖͍ͯͯ͠Δ
ϓϥΠϕʔτ"1*ΫϥΠΞϯτͷݱঢ় w ࣮ʹ౷Ұײ͕ͳ͍ w +40/Λσίʔυ͚ͨͩ͠ͷσʔλΛฦ͢ͷ͋ΕɺϞσϧ૬ͷΠϯελϯεΛฦ͢ͷ ͋Δ w ෳͷϦϙδτϦʹࢄ࣮ͯ͠͞Ε͍ͯΔ w ͦΕͧΕʹ"1*Λୟͨ͘ΊͷɾࢠΫϥε͕ଘࡏ͢Δ
w ผͷϦϙδτϦͷΫϥεΛܧঝͯ͠Δͷ͋Δ w Ϣχοτςετͷϝϯςφϯείετ w "1*ͷ༷Λม͑ͨΒQIQWDSͷϑΟΫενϟਓؒͷखͰमਖ਼͠ͳ͍ͱ͍͚ͳ͍ w ಉ͡Α͏ͳςετ͕ͨ͘͞Μ͋Δ
ΧΦεԽ·ͩ࢝·͔ͬͨΓ ͍·ͷ͏ͪʹखΛଧ͍ͪͨ
ཧ
4XBHHFS$PEFHFO
4XBHHFS$PEF(FOFSBUPS wIUUQTXBHHFSJPTXBHHFSDPEFHFO w0QFO"1*4XBHHFSʹԊͬͨఆ͔ٛΒ৭ʑͳݴޠɾϑϨʔϜϫʔΫͷαʔ όʔɺΫϥΠΞϯτɺςετελϒΛੜͰ͖Δ w࠷৽W wW ͦΖͦΖϦϦʔε ͔Β(V[[MF 143 Λ)551ΫϥΠΞϯτͱͯ͠
ར༻͍ͯ͠Δ w1)1Ҏ্
ΠϯετʔϧʙΫϥΠΞϯτੜ $ brew install swagger-codegen $ swagger-codegen generate \ -i
http://petstore.swagger.io/v2/swagger.json \ -l php \ -o . ಛఆͷόʔδϣϯΛ͍͍ͨ߹ $ git clone https://github.com/swagger-api/swagger-codegen $ ./run-in-docker.sh mvn package $ ./run-in-docker.sh generate \ -i http://petstore.swagger.io/v2/swagger.json \ -l php \ -o .
ੜ͞ΕΔϑΝΠϧ WҰ෦ൈਮ ├── lib │ ├── Api │ │ ├──
PetApi.php │ │ ├── StoreApi.php │ │ └── UserApi.php │ ├── ApiClient.php │ ├── Model │ │ ├── ApiResponse.php │ │ ├── Category.php │ │ ├── Order.php │ │ ├── Pet.php │ │ ├── Tag.php │ │ └── User.php
ϖοτετΞͷTXBHHFSKTPO { "paths": { "/pet/{petId}": { "get": { "operationId": “getPetById",
…… "definitions": { "Pet": { "type": "object", "properties": { "category": { "$ref": "#/definitions/Category" },
QFU\QFU*E^ͷϨεϙϯε { "id": 1, "category": { "id": 1, "name": "string"
}, "name": "doggie", "photoUrls": [ "string" ], "tags": [ { "id": 1,
ΫϥΠΞϯτͷ͍৺ (new \Swagger\Client\Api\PetApi)->getPetById(1); class Swagger\Client\Model\Pet#9 (1) { protected $container =>
array(6) { 'id' => int(1) 'category' => class Swagger\Client\Model\Category#10 (1) {
ΫϥΠΞϯτͷ͍৺ (new \Swagger\Client\Api\PetApi)->findPetsByStatus('sold') array(1424) { [0] => class Swagger\Client\Model\Pet#4239 (1)
{ } [1] => class Swagger\Client\Model\Pet#4243 (1) {
࣮ઓೖΛఆͨ͠՝ wϞσϧʹ࣮ΛՃ͍͑ͨ w$JSDVJU#SFBLFSΛ͍͍ͨ w4XBHHFS$PEFHFO $JSDVJU#SFBLFS (BOFTIB w IUUQTBDLJOUPTIHJUIVCJPCMPHTXBHHFSDPEFHFOXJUIHBOFTIB
ϋʔυϧ
࣮ݱ·Ͱͷϋʔυϧ w 0QFO"1*Ͱఆٛ͢Δ w ҰؾʹΔඞཁແ͍ͷͰͬͯ͘ w ϩʔΧϧڥͷվળ w 13͕͋ΔͷͰؤுΔʢՃ͓ئ͍͠·͢QSBZʣ w
࣮ઓೖΛఆͨ͠՝ w .PEFMʹ࣮ΛՃ͍͑ͨ߹Ͳ͏͢Δʁ w $JSDVJU#SFBLFSΛ͍͍ͨ߹Ͳ͏͢Δʁ w ӡ༻Ͳ͏͢Δʁ ࣍ͷεϥΠυ
ίʔυࣗಈੜͷϓϥΫςΟε w(FOFSBUJPO(BQύλʔϯ wIUUQTNBSUJOGPXMFSDPNETM$BUBMPHHFOFSBUJPO(BQIUNM wIUUQXXXIZVLJDPNEQEQJOGPIUNM(FOFSBUJPO(BQ wlॻ͖Ճ͑ͯͨ෦͕ফ͑ͯΔʜzΛ͙ wࣗಈੜ͞Εͨίʔυͱਓ͕ؒॻ͍ͨίʔυΛ͢Δ wੜ͞ΕͨίʔυͷαϒΫϥεʹਓ͕࣮ؒΛՃ͑Δ
.PEFMʹ࣮ΛՃ͍͑ͨ߹ͬͯʁ ࣮ྫͱͯ͠ɺطଘͷ.PEFMͷ࣮ΛݟͯΈΔ
(FOFSBUJPO(BQύλʔϯΛద༻͍͕ͨ͠ʜ (new \Swagger\Client\Api\PetApi)->getPetById(1); // class Swagger\Client\Model\Pet w1FUϞσϧʹखΛೖΕ͍ͨ w1FU"QJͷฦΓ͕1FUϞσϧ w1FUͷαϒΫϥεΛར༻͢Δ༨͕ແ͍ʜ
࣮ઓೖΛఆͨ͠՝ .PEFMʹ࣮ΛՃ͍͑ͨ wΦϦδφϧςϯϓϨʔτͱϑΝΫτϦΛ͏ wΦϦδφϧςϯϓϨʔτ wਓ͕ؒॻ͘αϒΫϥεΛར༻͢ΔͨΊͷԼΛ࡞Δ wϑΝΫτϦ w"1*ΫϥεͷੜΛ୲͢Δ w"1*Ϋϥε͕ฦ͖͢ϞσϧΛཧͤ͞Δ
.PEFMʹ࣮ΛՃ͍͑ͨΦϦδφϧςϯϓϨʔτ class PetApi { public function __construct( ClientInterface $client =
null, Configuration $config = null, HeaderSelector $selector = null, $modelClass = null w ಠࣗͷίʔυੜςϯϓϨʔτΛ༻ҙͯ͠ੜ͞ΕΔίʔυΛΧελϚΠζ͢Δ w TXBHHFSDPEFHFOHFOFSBUFͷUΦϓγϣϯ w ࣮ߦ݁Ռͱͯ͠ฦ͢ϞσϧΫϥεΛࠩ͠ସ͑ΒΕΔΑ͏ʹ͢ΔͨΊʹ࠷খݶͷΧ ελϚΠζΛ͢Δ
.PEFMʹ࣮ΛՃ͍͑ͨΦϦδφϧςϯϓϨʔτ Πϝʔδ
.PEFMʹ࣮ΛՃ͍͑ͨϑΝΫτϦ w ࣮ߦ݁Ռͱͯ͠ฦ͖͢ϞσϧΫϥεΛཧͤ͞Δ ApiFactory::instantiate(‘PetApi’)->getPetById(1); // class ……\Model\HandWrittenPet class ApiFactory {
private static $map = [‘PetApi’ => ‘HandWrittenPet’]; public static function instantiate($apiClass) { …… return new $apiClass(… , $modelClass);
.PEFMʹ࣮ΛՃ͍͑ͨϑΝΫτϦ Πϝʔδ
.PEFMʹ࣮ΛՃ͍͑ͨ ApiFactory::instantiate(‘PetApi’)->getPetById(1); // class Swagger\Client\Model\HandWrittenPet (new \Swagger\Client\Api\PetApi)->getPetById(1); // class Swagger\Client\Model\Pet
ϏϑΥʔ Ξϑλʔ ΦϦδφϧςϯϓϨʔτ ϑΝΫτϦͰ (FOFSBUJPO(BQύλʔϯΛద༻༷ͨ͠ࢠ
࣮ઓೖΛఆͨ͠՝ $JSDVJU#SFBLFSΛ͍͍ͨ wϑΝΫτϦΛ͏ w"1*ΫϥεΛ࡞Δͱ͖ʹɺ$JSDVJU#SFBLFSΛΈࠐΜͩ)551ΫϥΠΞ ϯτΛηοτ͢Δ
$JSDVJU#SFBLFSΛ͍͍ͨ class ApiFactory { public static function instantiate($apiClass) { ……
return new $apiClass($httpClientWithCB, … , $modelClass); w༧Ί$JSDVJU#SFBLFSΛΈࠐΜͩΫϥΠΞϯτ͕ηοτ͞Εͨ"1*Πϯελ ϯεΛฦ͢ w IUUQTBDLJOUPTIHJUIVCJPCMPHTXBHHFSDPEFHFOXJUIHBOFTIB w "QJ$MJFOUΛܧঝͨ͠ΫϥεΛ༻ҙ͢Δํ๏
$JSDVJU#SFBLFSΛ͍͍ͨ Πϝʔδ
ӡ༻ w ϓϥΠϕʔτ"1*ΫϥΠΞϯτઐ༻ͷϦϙδτϦΛ࡞Δ w ཁٻ͞ΕΔ1)1όʔδϣϯ͕ҧ͏ͷͰڞ༗ϦϙδτϦʹೖΕΒΕͳ͍ w Ϣχοτςετ w ਓ͕ؒॻ͘ίʔυ͚ͩςετΛॻ͚ྑ͍ͷͰ w
"1*ఆٛͱੜ͞ΕΔίʔυඞͣҰக͢Δ w "1*ͷৼΔ͍"1*ଆͷςετ͕อূ͢Δ w ։ൃͷྲྀΕ w "1*Λ࣮͢Δʗ0QFO"1*ͷఆٛΛॻ͘ w ΫϥΠΞϯτΛੜ͢ΔʗαϒΫϥεͷ࣮͕ඞཁͳΒΔ ςετΛॻ͘
ݱঢ়ˠ4XBHHFS$PEFHFOΛ͏ͱ w࣮ʹ౷Ұײ͕ͳ͍ wੜ͞ΕΔίʔυͰ͕උ͞Εɺ౷Ұײ͕ͰΔ wෳͷϦϙδτϦʹࢄ࣮ͯ͠͞Ε͍ͯΔ wઐ༻ͷϦϙδτϦʹ౷Ұ wϢχοτςετͷϝϯςφϯείετ wਓ͕ؒॻ͍ͨίʔυ͚ͩςετ͢Εྑ͍
ϨϏϡʔ͓ئ͍͠·͢