swagger-api / swagger-api/swagger-codegen

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

Open
#3,028 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Objc help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Objective-C request-generation code containing the shown cache-policy logic and the SWGApiClient cache setting. Reproduce a generated GET with produces: application/json, then verify that enabling local caching no longer causes the request to ignore cached data while JSON response serialization still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.