Swagger-codegen: timeout functioanlity

Created on 7 Jul 2017  路  3Comments  路  Source: swagger-api/swagger-codegen

i am using the latest Swagger Code-gen.

I need to be able to control the timeout time in the Swagger Generated API's.
Sometimes the application hangs loading just because I cant set the timeout.

I am using it on iOS Swift (Alamofire), and on Android (Volley)

Please help

Android Swift Question

Most helpful comment

@mn288 so I ended up manually adding a defaultTimeout in SwaggerClientAPI:
open class SwaggerClientAPI {
....
open static var defaultTimeout = URLSessionConfiguration.default.timeoutIntervalForRequest
.....
}
which can be overridden by my app, and then in AlamoFireImplementations.swift I manually created a session with this default timeout:

    // Create a new manager for each request to customize its request header
    let configuration = URLSessionConfiguration.default
    configuration.httpAdditionalHeaders = buildHeaders()
    configuration.timeoutIntervalForRequest = SwaggerClientAPI.defaultTimeout
    let manager = Alamofire.SessionManager(configuration: configuration)
    managerStore[managerId!] = manager

instead of calling createSessionManager()

you can do the same workaround for now and I can work on getting this into the tree so others can use it...

All 3 comments

@mn288 for Swift, I've no idea. cc @jaz-sh @Edubits @jgavris to see if they've any clue or example.

For Android (volley), there's a PR to make the timeout configurable. Would it help by reviewing the change?

@mn288 so I ended up manually adding a defaultTimeout in SwaggerClientAPI:
open class SwaggerClientAPI {
....
open static var defaultTimeout = URLSessionConfiguration.default.timeoutIntervalForRequest
.....
}
which can be overridden by my app, and then in AlamoFireImplementations.swift I manually created a session with this default timeout:

    // Create a new manager for each request to customize its request header
    let configuration = URLSessionConfiguration.default
    configuration.httpAdditionalHeaders = buildHeaders()
    configuration.timeoutIntervalForRequest = SwaggerClientAPI.defaultTimeout
    let manager = Alamofire.SessionManager(configuration: configuration)
    managerStore[managerId!] = manager

instead of calling createSessionManager()

you can do the same workaround for now and I can work on getting this into the tree so others can use it...

Brilliant; thank you for your efforts guys!

Was this page helpful?
0 / 5 - 0 ratings