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
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
AWSに止められる覚悟してますか?
morizo_1984
2
540
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
500
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
3.8k
ジョジョの世界をXRで再現する
mofurune
0
170
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Crafting Experiences
bethany
1
380
What's in a price? How to price your products and services
michaelherold
247
13k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Embracing the Ebb and Flow
colly
88
5.2k
Six Lessons from altMBA
skipperchong
29
4.5k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
ラッコキーワード サービス紹介資料
rakko
1
5.4M
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Product Roadmaps are Hard
iamctodd
55
13k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
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