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
swagger-codegen から眺める Swift4
Search
d_date
November 21, 2017
Programming
3
3.8k
swagger-codegen から眺める Swift4
2017/11/21(火) 関西モバイルアプリ研究会 in 関東
2017/11/28(火) potatotips #45
d_date
November 21, 2017
Tweet
Share
More Decks by d_date
See All by d_date
TCA Practice in 5 min
d_date
2
1.2k
waiwai-swiftpm-part2
d_date
3
470
わいわいSwift PM part 1
d_date
2
370
What's new in Firebase 2021
d_date
2
1.4k
CI/CDをミニマルに構築する
d_date
1
540
Swift Package centered project - Build and Practice
d_date
20
13k
How to write Great Proposal
d_date
4
1.2k
Thinking about Architecture for SwiftUI
d_date
8
2.3k
Integrate your app to modern world in Niigata
d_date
0
620
Other Decks in Programming
See All in Programming
ドメインイベント増えすぎ問題
h0r15h0
2
300
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
120
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
370
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
快速入門可觀測性
blueswen
0
350
From Translations to Multi Dimension Entities
alexanderschranz
2
130
Haze - Real time background blurring
chrisbanes
1
510
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
7k
Thoughts on Productivity
jonyablonski
67
4.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Docker and Python
trallard
42
3.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Transcript
Swagger-codegen͔Β ோΊΔSwift4 Daiki Matsudate / @d_date 2017/11/28 potatotips
Daiki Matsudate iOS Mobile App Engineer @d_date
None
None
None
None
None
͓Βͤ
None
https://firebase.asia/
͓Βͤᶄ
Tokyo 2018/3/1 - 3
͓Βͤᶅ
None
͓Βͤᶆ
None
͓Βͤᶇ
None
None
͔͜͜Βຊฤ
None
• APIͷ༷ΛYAMLͰཧ (OpenAPI2.0) • αʔόʔαΠυ / ΫϥΠΞϯταΠυͷίʔυੜ͕Մೳ • MockͨͯΒΕΔ
https://github.com/swagger-api/ swagger-codegen
SwaggerͰ࢝ΊΔAPIఆٛཧͱ ίʔυδΣωϨʔτ ɹ iOSDC 2017 2017/09/15@ૣҴాେֶཧֶ෦ૣҴాΩϟϯύε 63߸ؗ Yohei Suginami (
@susieyy ) https://speakerdeck.com/susieyy/swaggerdeshi-meruapiding-yi-guan-li-tokodozienereto
swagger-api / swagger-codegen swagger.yaml swagger-codegen -l swift4 -i swagger.yaml
Swagger Automation API.framework carthage build —-no-skip-current carthage archive
Swagger Codegen Swi!ͷରԠঢ়گ — Swift4ʹઈࢍରԠத — JSONͷύʔεCodableͰ࣮ — OptionalͷఆٛʹରԠ —
EnumରԠ — API Client෦Alamofire͕ϕʔε — CocoaPodsͷϥΠϒϥϦͱͯ͠ग़ྗͰ͖Δ — RxSwiftͱ࿈ܞՄೳʢ Ϩεϙϯε͕ObservableʹͳΔ ʣ https://speakerdeck.com/susieyy/swaggerdeshi-meruapiding-yi-guan-li-tokodozienereto?slide=17
Swagger Codegen Swi!ͷରԠঢ়گ — Swift4ʹઈࢍରԠத — JSONͷύʔεCodableͰ࣮ — OptionalͷఆٛʹରԠ —
EnumରԠ — API Client෦Alamofire͕ϕʔε — CocoaPodsͷϥΠϒϥϦͱͯ͠ग़ྗͰ͖Δ — RxSwiftͱ࿈ܞՄೳʢ Ϩεϙϯε͕ObservableʹͳΔ ʣ https://speakerdeck.com/susieyy/swaggerdeshi-meruapiding-yi-guan-li-tokodozienereto?slide=17
Swift4ʹઈࢍରԠத
Swift4ʹઈࢍରԠத master͕յΕ͍ͯΔ
Swift4ʹઈࢍରԠத… • Swift4ͳͷʹRxSwiftͷόʔδϣϯ͕3.xͰίϯύΠϧΤϥʔ • allOf: λάʹهࡌͨ͠$ref͕ܧঝؔʹͳΔͷʹinitͰ super.init(coder:)ΛݺΜͰ͍ͳ͍ͷͰίϯύΠϧΤϥʔ • ۭͷλϓϧͷมߋʹै͍ͯ͠ͳ͍ͷͰɺon(.next())ͰίϯύΠϧΤϥʔ •
enumΛStringͰσίʔυ͠Α͏ͱͯ͠ίϯύΠϧΤϥʔ • CodableΛҾʹͱΔϝιουʹAnyΛͦ͏ͱͯ͠ίϯύΠϧΤϥʔ
ࣗ࡞ͷmastachςϯϓϨʔτΛ࡞Δ
ΦϨΦϨYAML Parser & GeneratorΛ࡞Δ
https://github.com/hiragram/ Swako ΦϨΦϨYAML Parser & GeneratorΛ࡞Δ
None
PRΛૹΖ͏ʂʂ
ࣗྗͰ͢
Swift4ʹઈࢍରԠத… • Swift4ͳͷʹRxSwiftͷόʔδϣϯ͕3.xͰίϯύΠϧΤϥʔ • allOf: λάʹهࡌͨ͠$ref͕ܧঝؔʹͳΔͷʹinitͰ super.init(coder:)ΛݺΜͰ͍ͳ͍ͷͰίϯύΠϧΤϥʔ • ۭͷλϓϧͷมߋʹै͍ͯ͠ͳ͍ͷͰɺon(.next())ͰίϯύΠϧΤϥʔ •
enumΛStringͰσίʔυ͠Α͏ͱͯ͠ίϯύΠϧΤϥʔ • CodableΛҾʹͱΔϝιουʹAnyΛͦ͏ͱͯ͠ίϯύΠϧΤϥʔ
RxSwift in Swift 4 • ʮRxSwift4Λνϥݟ͢Δʯ@tarunon https://www.icloud.com/keynote/ 0lglRaoECYvXtcY3bkhRC1C7Q#OverviewRxSwift4
on(.next())ͰίϯύΠϧΤϥʔʁ ObserverʹVoidͷΠϕϯτΛͦ͏ͱ͢Δɻ open class func updatePet(body: Pet) -> Observable<Void> {
return Observable.create { observer -> Disposable in updatePet(body: body) { error in if let error = error { observer.on(.error(error)) } else { observer.on(.next()) } observer.on(.completed) } return Disposables.create() } }
on(.next())ͰίϯύΠϧΤϥʔʁ ObserverʹVoidͷΠϕϯτΛͦ͏ͱ͢Δɻ open class func updatePet(body: Pet) -> Observable<Void> {
return Observable.create { observer -> Disposable in updatePet(body: body) { error in if let error = error { observer.on(.error(error)) } else { observer.on(.next()) } observer.on(.completed) } return Disposables.create() } } Missing argument for parameter #1 in call
on(.next())ͰίϯύΠϧΤϥʔʁ ObserverʹVoidͷΠϕϯτΛͦ͏ͱ͢Δɻ open class func updatePet(body: Pet) -> Observable<Void> {
return Observable.create { observer -> Disposable in updatePet(body: body) { error in if let error = error { observer.on(.error(error)) } else { observer.on(.next(())) } observer.on(.completed) } return Disposables.create() } }
None
Swift4ͰλϓϧͱɺෳҾؔΛ۠ผ͢ΔΑ͏ʹͳͬͨ f f(()) ͱॻ͘
classܧঝͯ͠ΔͷʹɺsuperݺΜͰͳ͍ʁ open class Cat: Animal { public var declawed: Bool?
// Decodable protocol methods public override required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: String.self) declawed = try container.decodeIfPresent(Bool.self, forKey: "declawed") } } superݺΜͰͳ͍
classܧঝͯ͠ΔͷʹɺsuperݺΜͰͳ͍ʁ open class Cat: Animal { public var declawed: Bool?
// Decodable protocol methods public required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: String.self) declawed = try container.decodeIfPresent(Bool.self, forKey: "declawed") try super.init(from: decoder) } }
ͦͦɺͳΜͰܧঝ͕ؔൃੜ ͢ΔΜͰ͔͢ʁ
Cat: allOf: - $ref: '#/definitions/Animal' - type: object properties: declawed:
type: boolean Animal: type: object discriminator: className required: - className properties: className: type: string color: type: string default: 'red' = Animal + declawed open class Cat: Animal { public var declawed: Bool? }
ΫϥεΛܧঝͨ͠ΒͲ͏͔ʁ encode / decode Λ࣮ ܧঝͻͱͭͷΫϥε·Ͱ superclass ͷ มॻ͔ͳͯ͘ྑ͍
ΫϥεΛܧঝͨ͠ΒͲ͏͔ʁ encode / decode Λ࣮ → ίʔυੜͰͰ͖Δ ܧঝͻͱͭͷΫϥε·Ͱ superclass ͷ
มॻ͔ͳͯ͘ྑ͍
protocolΛద߹ͨ͠ΒͲ͏͔ʁ ద߹͢Δprotocolͷมॻ͔ͳ͚Ε͍͚ͳ͍ encode / decodeॻ͔ͳͯ͘ྑ͍ structͰॻ͚Δ
ίʔυੜʹ͓͚ΔϕετϓϥΫςΟε Կܧঝ͠ͳ͍
ίʔυੜʹ͓͚ΔϕετϓϥΫςΟε ͦͦBMM0GͷSFGऔಘͯ͠ɺଞͷมͱDPODBUͯ͘͠ ΕΕ͍͍Μ͡Όͳ͍͔ͳ͊
https://github.com/swagger-api/ swagger-codegen/issues/6941 classΛstructʹ͍ͨ͠
Swift4ʹઈࢍରԠத • Swift4 ͳͷʹ RxSwift ͷόʔδϣϯ͕ 3.x ͰίϯύΠϧΤϥʔ • allOf
λάʹهࡌͨ͠ ref ͕ܧঝؔʹͳΔͷʹinitͰsuper.init(coder:)Λݺ ΜͰ͍ͳ͍ͷͰίϯύΠϧΤϥʔ • ۭͷλϓϧͷมߋʹै͍ͯ͠ͳ͍ͷͰɺonNext()ͰίϯύΠϧΤϥʔ • enumΛStringͰσίʔυ͠Α͏ͱͯ͠ίϯύΠϧΤϥʔ • CodableΛҾʹͱΔϝιουʹAnyΛͦ͏ͱͯ͠ίϯύΠϧΤϥʔ
(ݩ͔Β) sampleյΕͯΔ͔Β͠ͱ͍ͯ
(ݩ͔Β) ςετ௨Βͳ͍Μ͚ͩͲ…
Ώͬ͘ΓٳΜͰ…
Swift4ʹઈࢍରԠத • Swift4ͳͷʹRxSwift, Alamofireͷόʔδϣϯ͕3.xͰίϯύΠϧΤϥʔ • allOf λάʹهࡌͨ͠ref ͕ܧঝؔʹͳΔͷʹinitͰsuper.init(coder:)Λݺ ΜͰ͍ͳ͍ͷͰίϯύΠϧΤϥʔ •
ۭͷλϓϧͷมߋʹै͍ͯ͠ͳ͍ͷͰɺonNext()ͰίϯύΠϧΤϥʔ • enumΛStringͰσίʔυ͠Α͏ͱͯ͠ίϯύΠϧΤϥʔ • CodableΛҾʹͱΔϝιουʹAnyΛͦ͏ͱͯ͠ίϯύΠϧΤϥʔ શ෦͠·ͨ͠
https://github.com/swagger-api/ swagger-codegen/pull/6921
Merge͞Εͨ͋ͱϝʔϧ͕དྷͨ
https://jknack.github.io/ handlebars.java/ Handling OpenAPI 3.0 with new engine
Recap • swagger-codegen ͷ Swift4 ରԠ͠·ͨ͠ • खऔΓૣ͘Λੜ͍ͨ͠ਓʹΦεεϝ • Codable
ͷܧঝؔʹ͍ͭͯɺ࠙ձͰ