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.3k
waiwai-swiftpm-part2
d_date
3
470
わいわいSwift PM part 1
d_date
2
380
What's new in Firebase 2021
d_date
2
1.4k
CI/CDをミニマルに構築する
d_date
1
550
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
630
Other Decks in Programming
See All in Programming
rails newと同時に型を書く
aki19035vc
5
710
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
450
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
450
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.4k
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
ゼロからの、レトロゲームエンジンの作り方
tokujiros
3
1.1k
functionalなアプローチで動的要素を排除する
ryopeko
1
220
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
700
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.9k
Amazon Nova Reelの可能性
hideg
0
200
ErdMap: Thinking about a map for Rails applications
makicamel
1
660
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Side Projects
sachag
452
42k
Why Our Code Smells
bkeepers
PRO
335
57k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Faster Mobile Websites
deanohume
305
30k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
Optimizing for Happiness
mojombo
376
70k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
A designer walks into a library…
pauljervisheath
205
24k
Become a Pro
speakerdeck
PRO
26
5.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
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
ͷܧঝؔʹ͍ͭͯɺ࠙ձͰ