Swift3: properly percent-escape path parameters (#6705)

* Add addiitional files from upstream

* Remove mis-added files

* Swift3: Properly percent-escape path parameters

This change fixes the following issue:

https://github.com/swagger-api/swagger-codegen/issues/6400

The problem was that path parameters were not properly percent-escaped before being placed into the URL path. This leads to creation of an invalid URL, which then fails.

So therefore, in the API template where path parameters are handled, we propertly percent escape them, using the characters which are allowed in URL paths.

In addition to this template change, then this PR includes the following changes:

1. Resulting changes in all generated code due to the above template change.
2. I added the objcCompatible run to the swift3-petstore-all.sh so that I could re-generated all of the generated code with a single script.
3. I added a unit test in UserAPITests.swift which verifies that paths are properly escaped.
4. In order to make the unit test work, then I needed access to RequestBuilder<T>.URLString to verify that the path was properly escaped. However, RequestBuilder<T>.URLString had "internal" access control so it was inaccessible from the unit test. So therefore, I made four contants in RequestBuilder<T> to be public. This should not harm anything, since they are constants ("let's") and cannot be changed from the outside of the class after initialization.
5. There were also some stray changes which look like they were caused by having not run bin/swift3-petstore-all.sh in a while.
This commit is contained in:
ehyche
2017-10-30 03:40:00 -04:00
committed by wing328
parent bc302f7151
commit 95ef1bf62e
84 changed files with 5188 additions and 69 deletions

View File

@@ -160,4 +160,14 @@ class UserAPITests: XCTestCase {
self.waitForExpectations(timeout: testTimeout, handler: nil)
}
func testPathParamsAreEscaped() {
// The path for this operation is /user/{userId}. In order to make a usable path,
// then we must make sure that {userId} is percent-escaped when it is substituted
// into the path. So we intentionally introduce a path with spaces.
let userRequestBuilder = UserAPI.getUserByNameWithRequestBuilder(username: "User Name With Spaces")
let urlContainsSpace = userRequestBuilder.URLString.contains(" ")
XCTAssert(!urlContainsSpace, "Expected URL to be escaped, but it was not.")
}
}