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
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Haze - Real time background blurring
chrisbanes
1
510
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
Symfony Mapper Component
soyuka
2
740
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
100
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
110
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
390
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
Go の GC の不得意な部分を克服したい
taiyow
3
790
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
0
110
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
Why Our Code Smells
bkeepers
PRO
335
57k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
A Modern Web Designer's Workflow
chriscoyier
693
190k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Building an army of robots
kneath
302
44k
Automating Front-end Workflow
addyosmani
1366
200k
Faster Mobile Websites
deanohume
305
30k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Embracing the Ebb and Flow
colly
84
4.5k
Facilitating Awesome Meetings
lara
50
6.1k
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
ͷܧঝؔʹ͍ͭͯɺ࠙ձͰ