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.1k
waiwai-swiftpm-part2
d_date
3
460
わいわいSwift PM part 1
d_date
2
370
What's new in Firebase 2021
d_date
2
1.4k
CI/CDをミニマルに構築する
d_date
1
530
Swift Package centered project - Build and Practice
d_date
20
13k
How to write Great Proposal
d_date
4
1.1k
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
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
役立つログに取り組もう
irof
28
9.6k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
CSC509 Lecture 11
javiergs
PRO
0
180
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Quine, Polyglot, 良いコード
qnighy
4
640
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
How STYLIGHT went responsive
nonsquared
95
5.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Producing Creativity
orderedlist
PRO
341
39k
Rails Girls Zürich Keynote
gr2m
94
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Gamification - CAS2011
davidbonilla
80
5k
GraphQLとの向き合い方2022年版
quramy
43
13k
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
ͷܧঝؔʹ͍ͭͯɺ࠙ձͰ