swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.85k stars 6.02k forks source link

[Swift] Alamofire client template does not support concurrent request #9321

Open jrcmramos opened 5 years ago

jrcmramos commented 5 years ago
Description

The current Alamofire client template implementation does not support concurrent requests. The static AlamofireRequestBuilder.execute method adds an instance of Alamofire.SessionManager to a global variable (managerStore) without any thread safe mechanism to avoid concurrent accesses. Therefore this can result, for example, in the deallocation of a Alamofire.SessionManager that might cancel the request. As result, the requests affect will return Error Domain=NSURLErrorDomain Code=-999 "cancelled".

Swagger-codegen version

2.3.1, 3.0.5

Swagger declaration file content or url

Not needed, all applications making concurrent requests using the Alamofire implementation of these version should experience the same issues.

Command line used for generation

swagger-codegen-2.3.1 generate -i http://localhost:8083/api-docs/v1/swagger.json -l swift4 -o swagger-client

Steps to reproduce

Dispatch several concurrent operation to a OperationQueue performing different API requests. Check if any of these calls resulted in a cancelled request.

Suggest a fix/enhancement

I can think about two different solutions that could help in the resolution of this problem:

keithcml commented 5 years ago

I hit the same issue, how to fix!? any workaround??

jrcmramos commented 5 years ago

As far as I am concerned, we cannot use another Alamofire client without touching the existing template or creating a new one.

AMiketta commented 5 years ago

i have done a quick fix for that in my pull request https://github.com/swagger-api/swagger-codegen/pull/9499