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
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Realtime API 入門
riofujimon
0
150
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
初めてDefinitelyTypedにPRを出した話
syumai
0
420
CSC509 Lecture 11
javiergs
PRO
0
180
最新TCAキャッチアップ
0si43
0
190
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
The Invisible Side of Design
smashingmag
298
50k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
YesSQL, Process and Tooling at Scale
rocio
169
14k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
A designer walks into a library…
pauljervisheath
204
24k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
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
ͷܧঝؔʹ͍ͭͯɺ࠙ձͰ