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
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
5.8k
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
ふつうのFeature Flag実践入門
irof
7
3.9k
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
190
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
200
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
RTSPクライアントを自作してみた話
simotin13
0
600
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
330
dRuby over BLE
makicamel
2
340
3Dシーンの圧縮
fadis
1
770
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
550
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
Game over? The fight for quality and originality in the time of robots
wayneb77
1
200
Leo the Paperboy
mayatellez
7
1.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Scaling GitHub
holman
464
140k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
430
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
130
How STYLIGHT went responsive
nonsquared
100
6.2k
GitHub's CSS Performance
jonrohan
1033
470k
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