OpenAPITools / OpenAPITools/openapi-generator
[BUG][swift5] Generated client ignores redirection
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Generated OpenAPI client follows all redirection instead of handling described 3xx response cases.
Probably, URLSessionImplementations.swift should be extended with
func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void)
delegate method
openapi-generator version
5.4.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Redirect example
contact:
email: krasylnikov@gmail.com
version: "1.0"
servers:
- url: http://wikipedia.com
paths:
/:
get:
responses:
200:
description: OK
301:
description: Clients should follow the `Location` header to get the new URI.
headers:
Location:
description: URI where the client can get the new URI.
schema:
type: string
format: uri
302:
description: Clients should follow the `Location` header to get the new URI.
headers:
Location:
description: URI where the client can get the new URI.
schema:
type: string
format: uri
components: {}
Generation Details
openapi-generator generate -i redirect.yaml -g swift5 -o OpenAPI
Steps to reproduce
- Generate OpenAPI client with given yaml and command line.
- Import it to AppDelegate as import OpenAPIClient
- Call
DefaultAPI.rootGet(completion:{ data, error in
})
Expected result:
The "data" variable contains redirection URI to https://www.wikipedia.org/ (instead of original http://wikipedia.com)
Actual result:
The "data" variable is empty, generated client silently performs redirection
Related issues/PRs
Suggest a fix
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 with URLSessionImplementations.swift and reproduce the generated swift5 client using redirect.yaml and the stated openapi-generator command. Verify the DefaultAPI.rootGet call against the documented 3xx responses; done means the client handles the redirect response rather than silently following it and returning empty data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, swift
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100