You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
auto generated swift client problem - headers missing #1345
I created an auto generated swift client with swagger-codegen, and successfully imported into my xcode project. However, it seems that there's no logic for sending custom headers unlike other sdks.
Seems Ok with Python and Ruby SDK to call server with valid custom headers, but only swift SDK seems missing to sending headers.
Does passing custom headers with auto generated swift client is possible?
Right. I mean about api_key. I'll use custom header for API Key. Other clients supports api_key_prefix to store api_keys, and clients sending that headers with.
I am doing this way and it works for me, however, solution for globally defined custom header would be great. Currently you can only add Basic HTTP Auth header, which - IMHO is IMHO quite useless - I can't imagine any service authenticating that way.
I updated Swift template so you can add custom headers to dictionary defined in {{name}}API class.
I works for me (my app's backend need custom authentication header) so I think I will submit a PR.
Activity
wing328 commentedon Oct 7, 2015
@inska can you tell us a bit more about the custom header? Is that required for all HTTP requests? Is that for authentication?
inska commentedon Oct 8, 2015
Right. I mean about api_key. I'll use custom header for API Key. Other clients supports api_key_prefix to store api_keys, and clients sending that headers with.
Thanks!
wing328 commentedon Oct 8, 2015
@inska Likely that has not been implemented in the Swift client and we would appreciate the contribution from you and the community to add that.
tomekc commentedon Oct 21, 2015
You can work this around actually:
When calling
DefaultApi.yourMethod, the return value is RequestBuilder.In RequestBuilder you can call
rb.addHeader(name: "Authorization", value: "Bearer \(config.accessToken)")I am doing this way and it works for me, however, solution for globally defined custom header would be great. Currently you can only add Basic HTTP Auth header, which - IMHO is IMHO quite useless - I can't imagine any service authenticating that way.
tomekc commentedon Oct 28, 2015
I updated Swift template so you can add custom headers to dictionary defined in {{name}}API class.
I works for me (my app's backend need custom authentication header) so I think I will submit a PR.
tomekc commentedon Nov 2, 2015
Created PR #1492 - a generic solution to add any header to all requests.