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.77k stars 6.02k forks source link

[SWIFT] Alamofire Serialization on another queue than main #7783

Open ghost opened 6 years ago

ghost commented 6 years ago
Description

There is a problem in the AlamofireDecodableRequestBuilder class or maybe rather a lack of way to make serialization of responses run on another queue than the main queue.

In the processRequest method there is multiple cases on how to handle the response based on the data type. In Alamofire it is possible to pass a queue to run the serialization on. With large amounts of data this is causing the main thread to be blocked (locking up the user interface).

Docs on how to do it in Alamofire:

https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#response-mapping

Swagger-codegen version

2.3.1

Command line used for generation

java -jar $jar_codegen_file generate -i $json_spec_file -o . -l swift4 --additional-properties responseAs=RxSwift --additional-properties unwrapRequired=true

Steps to reproduce
  1. Generate Swift code from Swagger spec.
  2. Serialize big amounts of data
  3. Main thread is being blocked
Suggest a fix/enhancement

Make it possible to generate AlamofireDecodableRequestBuilder with a specific queue which the serialization should happen on.

ghost commented 6 years ago

I solved the problem by creating a AlamofireImplementations.mustache template with a queue specified. But should there be another way to do this?

joeboyscout04 commented 6 years ago

Hey there @afetrifork do you have a PR for this yet? My idea would be to pass in a queue object into the AlamofireRequestBuilder execute() and processRequest() methods.

Then swagger user could use their own requestBuilderFactory which overrides execute() to specify the queue.

ghost commented 6 years ago

I didn't create a PR for this, but I fixed the issue by creating a custom AlamofireImplementations template. I think it would be a good idea to allow passing in a queue