Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
iOS ライブラリをセルフサービスで生成する仕組み
Search
Yusuke Ohashi
September 11, 2022
Programming
2.7k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iOS ライブラリをセルフサービスで生成する仕組み
https://fortee.jp/iosdc-japan-2022/proposal/db912d81-3d13-46bd-81e1-8ae6dcc9e7b6
Yusuke Ohashi
September 11, 2022
Other Decks in Programming
See All in Programming
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
240
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
180
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.9k
What We Talk About When We Talk About XP
m_seki
2
620
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
250
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
380
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
710
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
110
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
470
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
240
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
620
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
110
Featured
See All Featured
Accessibility Awareness
sabderemane
1
210
sira's awesome portfolio website redesign presentation
elsirapls
0
410
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.8k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
580
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
520
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
650
Prompt Engineering for Job Search
mfonobong
0
450
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
360
Speed Design
sergeychernyshev
33
2.1k
Transcript
iOSライブラリをセルフサービスで⽣成する仕組み Sep 11th, 2022 Yusuke Ohashi Architect & SRE Group/Mobile
Core Team Rakuten Group, Inc.
2 ⾃⼰紹介 Yusuke Ohashi Application Architect@Rakuten Group, Inc. LT at
iOSDC 2016(初のiOSDC) in 練⾺ https://github.com/junkpiano https://yusuke.cloud
3 What Architect team is doing Standardization Productivity Innovation Cross-Platform,
Cross-Functional team - ソリューションの提供、標準化 - 技術調査、選定 - 開発者の⽣産性向上
4 セルフサービスとは
5 セルフサービスとは
6 セルフサービスとは アプリ、APIを 指定 ユーザーへ デリバリー APIクライアン トの⽣成
7 Agenda 〜セルフサービスへの道のり〜 背景〜OASの導⼊〜 ⾃動化の仕組みの構築 〜サーバーサイドの整備〜 ⾃動化の仕組みの構築 〜ツール&UIの開発〜 Swiftコード⽣成の実例 まとめ&告知
8 OASとは - https://www.openapis.org/ - Open API Specificationの略 - APIのデザインドキュメンテーション
- Method - Headers - Parameters - Response - Etc. - YAML, JSONで記述 - Swaggerとの違い - ここではOASの実装やツールの総称としてSwaggerを使う - https://swagger.io/blog/api-strategy/difference-between-swagger-and-openapi/
9 OASとは
10 OASとは Swagger UI https://petstore.swagger.io
11 OASとは Swagger Codegen – Client SDK/Server Stub Generator https://swagger.io/tools/swagger-codegen/
https://github.com/swagger-api/swagger-codegen
12 背景〜OASの導⼊〜
13 APIの乱⽴によるクライアントの複雑化
14 背景 〜OASの導⼊〜 API API API API API API *
2022/08/01 時点
15 背景 〜OASの導⼊〜 - クライアントにロジックが集中 - スパゲッティコード化しやすい - iOS/Androidで機能の差分が出る
16 モバイルアプリの機能に合わせたAPIへ
17 背景 〜OASの導⼊〜 BFF API Gateway API Gateway API API
API API API API How to design? * 2022/08/01 時点
18 BFFのデザインにOASを導⼊
19 背景〜OASの導⼊〜 デザイン ->実装 ⾃動化への基盤 開発者の負担減
20 ⾃動化の仕組みの構築〜サーバーサイド〜
21 OpenAPI Specificationの管理 Jenkins logo by https://jenkins.io/
22 OpenAPI Specificationの管理 - API ProviderがGitで管理 - Pull RequestでAPIスペックのレビュー -
Mobileのエンジニアも修正に参加
23 OpenAPI Specificationの管理 - Open API Specificationのガイドライン - Yamlのvalidationツールの使⽤ -
$refをまとめるための、Bundleツールの開発
24 ここまでがOASの仕込み
25 ⾃動化の仕組みの構築〜UI及びツールの開発〜
26 Code Generatorの開発
27 ⾃前のCode Generatorの開発 - すでにコード⽣成機能は実装されている - なぜ⾃前のcode generatorが必要なのか︖
28 ⾃前のCode Generatorの開発 Official Custom 不要な依存 あり なし テンプレート変更 難
容易 テスト モックライブ ラリなどで可 能 容易
29 ⾃前のCode Generatorの開発 ⾃前のcustom code generatorを作る。 Þ作り⽅ → https://github.com/swagger-api/swagger-codegen/tree/3.0.0 -
making-your-own- codegen-modules Þこちらで出来たJavaの雛形(maven project)を基にcode generatorを作成 Þテンプレート(mustache)は既存のSwift⽤の実装を参照 ÞJavaの⽅は継承元のクラスから実装を参照 Þドキュメントに乏しい。コードを読みながら書く。
30 ⾃前のCode Generatorの開発 〜OASの拡張〜 OASのServerブロックを拡張する例 -> サーバーに名前を追加(Vendor Extension)
31 ⾃前のCode Generatorの開発 〜OASの拡張〜 Yaml, テンプレートの変更例
32 ⾃前のCode Generatorの開発 〜OASの拡張〜 - 公式のものを使うか、カスタマイズするかは利便性と メンテナンス性のトレードオフ - チームの優先順位に応じて決める -
Swiftによる実装もあり(未検証) - https://github.com/yonaskolb/SwagGen
33 誰がコードを⽣成するのか︖
34 Jenkins Jenkins logo by https://jenkins.io/
35 Jenkins as Frontend Jenkins is - ⾔わずと知れたCIエンジン - ⾃由な拡張性
- 豊富なプラグイン - Web Applicationにもなる(APIもある)
36 Jenkins as Frontend Jenkins logo by https://jenkins.io/ Slave Node
Master Node
37 Master Node WebのフロントエンドとしてのJenkins Active Choices https://plugins.jenkins.io/uno-choice/ GroovyスクリプトでDynamicなFormを構築 e.g.) アプリごとに異なるAPI及びバージョンのリストをREST
APIで取得
38 Master Node
39 Master Node https://www.cncf.io/blog/2022/04/06/how-to-render-jenkins-build-parameters-dynamically/
40 Slave Node Lint - Push Podspec - Push SDK
Git Git - Pull OAS - Code generation
41 Delivery Jenkins logo by https://jenkins.io/ Developers
42 Swiftコード⽣成の実例
43 Swift Package Manager対応
44 Package.swift.mustache // swift-tools-version:5.2 // The swift-tools-version declares the minimum
version of Swift required to build this package. import PackageDescription let package = Package( name: "{{projectName}}", platforms: [.iOS(.v11), .watchOS(.v4)], products: [ .library(name: "{{projectName}}", targets: ["{{projectName}}"]), ], dependencies: [ ], targets: [ .target(name: "{{projectName}}", dependencies: []), ], swiftLanguageVersions: [.v5] )
45 Package.swift // swift-tools-version:5.2 // The swift-tools-version declares the minimum
version of Swift required to build this package. import PackageDescription let package = Package( name: ”SampleLib", platforms: [.iOS(.v11), .watchOS(.v4)], products: [ .library(name: ”SampleLib", targets: [”SampleLib"]), ], dependencies: [ ], targets: [ .target(name: ”SampleLib", dependencies: []), ], swiftLanguageVersions: [.v5] )
46 Protocolと実装クラスの⽣成
47 Protocolと実装クラスの⽣成 public protocol {{classname}}Protocol { {{#operation}} /** {{#summary}} {{{summary}}}
{{/summary}} {{#allParams}} - parameter {{paramName}}: ... {{/allParams}} - parameter completion: completion handler to receive the data and the error objects */ func {{operationId}}({{#allParams}}...{{/allParams}}{{#hasParams}}, {{/hasParams}} completion: @escaping ((_ response: {{{returnType}}}?, _ urlresponse: URLResponse?, _ error: Error?) -> Void)) -> URLSessionTask? {{/operation}} }
48 Protocolと実装クラスの⽣成 public protocol SampleListBFFAPIProtocol { /** SampleList API for
iOSDC 2022 - parameter authorization: (header) Authorization token - parameter completion: completion handler */ func sampleList(authorization: String, completion: @escaping ((_ response: SampleListResponse?, _ urlresponse: URLResponse?, _ error: Error?) -> Void)) -> URLSessionDataTask? }
49 Protocolと実装クラスの⽣成
50 Protocolと実装クラスの⽣成 public class SampleListBFFAPI: SampleListBFFAPIProtocol { /** SampleList API
for iOSDC 2022 - parameter authorization: (header) Authorization token - parameter completion: completion handler */ @discardableResult public func sampleList(authorization: String, completion: @escaping ((_ response: SampleListResponse?, _ urlresponse: URLResponse?, _ error: Error?) -> Void)) -> URLSessionDataTask? { return ... } }
51 Swift Concurrency対応
52 Concurrency対応 /** {{#summary}} {{{summary}}} {{/summary}} {{#allParams}} - parameter {{paramName}}:
... {{/allParams}} */ @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) func {{operationId}}({{#allParams}}...{{/allParams}}) async throws -> {{{returnType}}}
53 Concurrency対応 /** SampleListAPI for iOSDC 2022 - parameter authorization:
(header) Authorization token. */ @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) public func sampleListAPI(authorization: String) async throws -> SampleListResponse { let request = ... return try await session.sendRequest(with: request) }
54 Tips - 無いファイルを追加するときはcode generatorの実装が不可⽋ - Package.swiftの実装 - Protocolの定義など -
本当に複雑な処理は素直に別にライブラリにする⽅が無難 - ネットワークの実装は単独のライブラリ(共通の実装) - 独⾃の認証処理など - Templateにちょっと何か付け⾜すくらいなら公式のcode generatorで⼗分 - 若⼲の処理の変更 - 関数にコメントを加えるなど
55 まとめ
56 Takeaways OASベースのコード⽣成の仕組みの整備 Jenkinsを利⽤したセルフサービスのUI構築 ツール内製の強みを⽣かしたテンプレートの拡張 Swiftはテンプレートに馴染みやすい⾔語
57
None