-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift3: non dictionary body type #6531
Merged
wing328
merged 6 commits into
swagger-api:master
from
anozaki:swift3-non-dictionary-body-type
Sep 28, 2017
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ab157a4
Adding support for non dictionary body types.
733f055
Adding test for rest of the swift3 types
acf5388
Cleaning up implementation of makeRequest and adding better error han…
4eedf6f
Adding ClientError for error produced before request is sent.
43e22a1
Changing how encoding of body data is handled.
b627f3d
Cleaning up code that was modified.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// AnotherFakeAPI.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
|
||
open class AnotherFakeAPI: APIBase { | ||
/** | ||
To test special tags | ||
- parameter body: (body) client model | ||
- parameter completion: completion handler to receive the data and the error objects | ||
*/ | ||
open class func testSpecialTags(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { | ||
testSpecialTagsWithRequestBuilder(body: body).execute { (response, error) -> Void in | ||
completion(response?.body, error) | ||
} | ||
} | ||
|
||
|
||
/** | ||
To test special tags | ||
- PATCH /another-fake/dummy | ||
- To test special tags | ||
|
||
- examples: [{contentType=application/json, example={ | ||
"client" : "client" | ||
}}] | ||
- parameter body: (body) client model | ||
- returns: RequestBuilder<Client> | ||
*/ | ||
open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder<Client> { | ||
let path = "/another-fake/dummy" | ||
let URLString = PetstoreClientAPI.basePath + path | ||
let parameters = body.encodeToJSON() | ||
|
||
let url = NSURLComponents(string: URLString) | ||
|
||
let requestBuilder: RequestBuilder<Client>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() | ||
|
||
return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...etstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// FakeClassnameTags123API.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
|
||
open class FakeClassnameTags123API: APIBase { | ||
/** | ||
To test class name in snake case | ||
- parameter body: (body) client model | ||
- parameter completion: completion handler to receive the data and the error objects | ||
*/ | ||
open class func testClassname(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { | ||
testClassnameWithRequestBuilder(body: body).execute { (response, error) -> Void in | ||
completion(response?.body, error) | ||
} | ||
} | ||
|
||
|
||
/** | ||
To test class name in snake case | ||
- PATCH /fake_classname_test | ||
- API Key: | ||
- type: apiKey api_key_query (QUERY) | ||
- name: api_key_query | ||
- examples: [{contentType=application/json, example={ | ||
"client" : "client" | ||
}}] | ||
- parameter body: (body) client model | ||
- returns: RequestBuilder<Client> | ||
*/ | ||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> { | ||
let path = "/fake_classname_test" | ||
let URLString = PetstoreClientAPI.basePath + path | ||
let parameters = body.encodeToJSON() | ||
|
||
let url = NSURLComponents(string: URLString) | ||
|
||
let requestBuilder: RequestBuilder<Client>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() | ||
|
||
return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something but do you need this if block? if you change parameters to an Any? like you have instead of a dict, won't ParameterEncoding.encode() do exactly what you have here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm... now that I'm looking at how the ParameterEncoding and Manager works I think something like this is cleaner. I think the function should also be changed to throws so we can handle errors better. Then change the execute to use do/catch and generate a proper error.
The main problem with Alamofire is that parameter is defined as
Parameters
which is a typedef of [String: Any]. If you want to specify anything else they make you do everything your self.Let me try making these changes and run some tests.