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
iOS ライブラリをセルフサービスで生成する仕組み
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yusuke Ohashi
September 11, 2022
Programming
2.6k
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
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.2k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.7k
OSもどきOS
arkw
0
570
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
5.4k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
870
Creating Composable Callables in Contemporary C++
rollbear
0
150
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
180
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
140
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.3k
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
300
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Optimizing for Happiness
mojombo
378
71k
Abbi's Birthday
coloredviolet
2
8.1k
GitHub's CSS Performance
jonrohan
1033
470k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
Writing Fast Ruby
sferik
630
63k
Scaling GitHub
holman
464
140k
Context Engineering - Making Every Token Count
addyosmani
9
970
Claude Code のすすめ
schroneko
67
230k
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