Skip to content

Commit 5b06417

Browse files
Daiki Matsudatewing328
authored andcommitted
[swift4] Use RequestBuilder directly for RxSwift and PromiseKit (OpenAPITools#1718)
* remove default implementation * avoid insert blank lines
1 parent 8f7f227 commit 5b06417

File tree

51 files changed

+310
-1498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+310
-1498
lines changed

modules/openapi-generator/src/main/resources/swift4/api.mustache

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ open class {{classname}} {
3333

3434
{{/isEnum}}
3535
{{/allParams}}
36+
{{^usePromiseKit}}
37+
{{^useRxSwift}}
3638
/**
3739
{{#summary}}
3840
{{{summary}}}
@@ -54,7 +56,8 @@ open class {{classname}} {
5456
{{/returnType}}
5557
}
5658
}
57-
59+
{{/useRxSwift}}
60+
{{/usePromiseKit}}
5861
{{#usePromiseKit}}
5962
/**
6063
{{#summary}}
@@ -65,11 +68,19 @@ open class {{classname}} {
6568
*/
6669
open class func {{operationId}}({{#allParams}} {{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {
6770
let deferred = Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>.pending()
68-
{{operationId}}({{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { data, error in
71+
{{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}).execute { (response, error) -> Void in
6972
if let error = error {
7073
deferred.reject(error)
74+
{{#returnType}}
75+
} else if let response = response {
76+
deferred.fulfill(response.body!)
77+
} else {
78+
fatalError()
79+
{{/returnType}}
80+
{{^returnType}}
7181
} else {
72-
deferred.fulfill(data!)
82+
deferred.fulfill(())
83+
{{/returnType}}
7384
}
7485
}
7586
return deferred.promise
@@ -85,13 +96,21 @@ open class {{classname}} {
8596
*/
8697
open class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {
8798
return Observable.create { observer -> Disposable in
88-
{{operationId}}({{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { data, error in
99+
{{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}).execute { (response, error) -> Void in
89100
if let error = error {
90-
observer.on(.error(error))
101+
observer.onError(error)
102+
{{#returnType}}
103+
} else if let response = response {
104+
observer.onNext(response.body!)
105+
} else {
106+
fatalError()
107+
{{/returnType}}
108+
{{^returnType}}
91109
} else {
92-
observer.on(.next(data!))
110+
observer.onNext(())
111+
{{/returnType}}
93112
}
94-
observer.on(.completed)
113+
observer.onCompleted()
95114
}
96115
return Disposables.create()
97116
}

samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ open class AnotherFakeAPI {
2323
}
2424
}
2525

26-
2726
/**
2827
To test special tags
2928
- PATCH /another-fake/dummy

samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ open class FakeAPI {
2222
}
2323
}
2424

25-
2625
/**
2726
- POST /fake/outer/boolean
2827
- Test serialization of outer boolean types
@@ -52,7 +51,6 @@ open class FakeAPI {
5251
}
5352
}
5453

55-
5654
/**
5755
- POST /fake/outer/composite
5856
- Test serialization of object with outer number type
@@ -82,7 +80,6 @@ open class FakeAPI {
8280
}
8381
}
8482

85-
8683
/**
8784
- POST /fake/outer/number
8885
- Test serialization of outer number types
@@ -112,7 +109,6 @@ open class FakeAPI {
112109
}
113110
}
114111

115-
116112
/**
117113
- POST /fake/outer/string
118114
- Test serialization of outer string types
@@ -146,7 +142,6 @@ open class FakeAPI {
146142
}
147143
}
148144

149-
150145
/**
151146
- PUT /fake/body-with-file-schema
152147
- For this test, the body for this request much reference a schema named `File`.
@@ -181,7 +176,6 @@ open class FakeAPI {
181176
}
182177
}
183178

184-
185179
/**
186180
- PUT /fake/body-with-query-params
187181
- parameter query: (query)
@@ -215,7 +209,6 @@ open class FakeAPI {
215209
}
216210
}
217211

218-
219212
/**
220213
To test \"client\" model
221214
- PATCH /fake
@@ -264,7 +257,6 @@ open class FakeAPI {
264257
}
265258
}
266259

267-
268260
/**
269261
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
270262
- POST /fake
@@ -408,7 +400,6 @@ open class FakeAPI {
408400
}
409401
}
410402

411-
412403
/**
413404
To test enum parameters
414405
- GET /fake
@@ -473,7 +464,6 @@ open class FakeAPI {
473464
}
474465
}
475466

476-
477467
/**
478468
Fake endpoint to test group parameters (optional)
479469
- DELETE /fake
@@ -525,7 +515,6 @@ open class FakeAPI {
525515
}
526516
}
527517

528-
529518
/**
530519
test inline additionalProperties
531520
- POST /fake/inline-additionalProperties
@@ -561,7 +550,6 @@ open class FakeAPI {
561550
}
562551
}
563552

564-
565553
/**
566554
test json serialization of form data
567555
- GET /fake/jsonFormData

samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ open class FakeClassnameTags123API {
2323
}
2424
}
2525

26-
2726
/**
2827
To test class name in snake case
2928
- PATCH /fake_classname_test

samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ open class PetAPI {
2727
}
2828
}
2929

30-
3130
/**
3231
Add a new pet to the store
3332
- POST /pet
@@ -66,7 +65,6 @@ open class PetAPI {
6665
}
6766
}
6867

69-
7068
/**
7169
Deletes a pet
7270
- DELETE /pet/{petId}
@@ -117,7 +115,6 @@ open class PetAPI {
117115
}
118116
}
119117

120-
121118
/**
122119
Finds Pets by status
123120
- GET /pet/findByStatus
@@ -155,7 +152,6 @@ open class PetAPI {
155152
}
156153
}
157154

158-
159155
/**
160156
Finds Pets by tags
161157
- GET /pet/findByTags
@@ -193,7 +189,6 @@ open class PetAPI {
193189
}
194190
}
195191

196-
197192
/**
198193
Find pet by ID
199194
- GET /pet/{petId}
@@ -235,7 +230,6 @@ open class PetAPI {
235230
}
236231
}
237232

238-
239233
/**
240234
Update an existing pet
241235
- PUT /pet
@@ -275,7 +269,6 @@ open class PetAPI {
275269
}
276270
}
277271

278-
279272
/**
280273
Updates a pet in the store with form data
281274
- POST /pet/{petId}
@@ -322,7 +315,6 @@ open class PetAPI {
322315
}
323316
}
324317

325-
326318
/**
327319
uploads an image
328320
- POST /pet/{petId}/uploadImage
@@ -369,7 +361,6 @@ open class PetAPI {
369361
}
370362
}
371363

372-
373364
/**
374365
uploads an image (required)
375366
- POST /fake/{petId}/uploadImageWithRequiredFile

samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ open class StoreAPI {
2727
}
2828
}
2929

30-
3130
/**
3231
Delete purchase order by ID
3332
- DELETE /store/order/{order_id}
@@ -61,7 +60,6 @@ open class StoreAPI {
6160
}
6261
}
6362

64-
6563
/**
6664
Returns pet inventories by status
6765
- GET /store/inventory
@@ -95,7 +93,6 @@ open class StoreAPI {
9593
}
9694
}
9795

98-
9996
/**
10097
Find purchase order by ID
10198
- GET /store/order/{order_id}
@@ -130,7 +127,6 @@ open class StoreAPI {
130127
}
131128
}
132129

133-
134130
/**
135131
Place an order for a pet
136132
- POST /store/order

samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ open class UserAPI {
2727
}
2828
}
2929

30-
3130
/**
3231
Create user
3332
- POST /user
@@ -63,7 +62,6 @@ open class UserAPI {
6362
}
6463
}
6564

66-
6765
/**
6866
Creates list of users with given input array
6967
- POST /user/createWithArray
@@ -98,7 +96,6 @@ open class UserAPI {
9896
}
9997
}
10098

101-
10299
/**
103100
Creates list of users with given input array
104101
- POST /user/createWithList
@@ -133,7 +130,6 @@ open class UserAPI {
133130
}
134131
}
135132

136-
137133
/**
138134
Delete user
139135
- DELETE /user/{username}
@@ -168,7 +164,6 @@ open class UserAPI {
168164
}
169165
}
170166

171-
172167
/**
173168
Get user by user name
174169
- GET /user/{username}
@@ -203,7 +198,6 @@ open class UserAPI {
203198
}
204199
}
205200

206-
207201
/**
208202
Logs user into the system
209203
- GET /user/login
@@ -243,7 +237,6 @@ open class UserAPI {
243237
}
244238
}
245239

246-
247240
/**
248241
Logs out current logged in user session
249242
- GET /user/logout
@@ -278,7 +271,6 @@ open class UserAPI {
278271
}
279272
}
280273

281-
282274
/**
283275
Updated user
284276
- PUT /user/{username}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.3.4-SNAPSHOT
1+
4.0.0-SNAPSHOT

samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ open class AnotherFakeAPI {
2323
}
2424
}
2525

26-
2726
/**
2827
To test special tags
2928
- PATCH /another-fake/dummy

0 commit comments

Comments
 (0)