swagger-api/swagger-codegen

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

Open

#3.028 aberto em 2 de jun. de 2016

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)HTML (5.474 forks)batch import
Client: ObjcIssue: Bughelp wanted

Métricas do repositório

Stars
 (12.701 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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.

Guia do colaborador