swagger-api/swagger-codegen

[ObjC] Client local cache ignored when Accept header is set

Open

#3.028 geöffnet am 2. Juni 2016

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)HTML (5.474 Forks)batch import
Client: ObjcIssue: Bughelp wanted

Repository-Metriken

Stars
 (12.701 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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
  1. Define a GET request with the produces clause and no other headers
  2. Output the Objective-C Swagger Client and add to a project
  3. Enable caching using [SWGApiClient setCacheEnabled:YES];
  4. 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.

Contributor Guide