[ObjC] Client local cache ignored when Accept header is set
#3028 aperta il 2 giu 2016
Metriche repository
- Star
- (12.701 star)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Description
When specifying
produces: - application/json
in the YAML for a GET request, the Objective-C code generated adds the 'Accept' header with a value of 'application/json'.
This will cause the client caching to be effectively disabled, even after explicitly enabling the local caching using:
[SWGApiClient setCacheEnabled:YES];
The NSUrlRequest defaults to NSURLRequestReloadIgnoringLocalCacheData in this instance via the following code snippet:
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) { SWGDebugLog(@"%@ cache enabled", resourcePath); [request setCachePolicy:NSURLRequestUseProtocolCachePolicy]; } else { SWGDebugLog(@"%@ cache disabled", resourcePath); [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; }
For reference, removing the
produces: - application/json
clause, appears to break the JSON serialization of response returned with the 'Content-Type' header set to 'application/json'.
Swagger-codegen version
- API version: 0.1.0
- Package version:
- Build date: 2016-06-02T13:34:32.882Z
- Build package: class io.swagger.codegen.languages.ObjcClientCodegen
Swagger declaration file content or url
Adding the following to a GET request declaration:
produces: - application/json
Command line used for generation
N/A Built Objective-C client via online editor.
Steps to reproduce
- Define a GET request with the produces clause and no other headers
- Output the Objective-C Swagger Client and add to a project
- Enable caching using
[SWGApiClient setCacheEnabled:YES]; - Build and run
Observe local cache is ignored due to 'Accept' header being set.
Related issues
Unknown
Suggest a Fix
Check the headers with a white-list of 'static' request headers that shouldn't affect the use of the local cache.