swagger-api / swagger-api/swagger-codegen
[ObjC] Client local cache ignored when Accept header is set
Nobody has claimed this yet.
- 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
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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