-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QueryParam's order #119
Comments
Could you please provide the error you got, when you tried to use Appz to add this application ? |
It's not the |
Thanks for reporting this! public enum QuerySortStrategy {
case none
case array([String])
case callback((String, String) -> Bool)
}
public struct Path {
public var pathComponents = [String]()
public var queryParameters = [String:String]()
public var querySortStrategy = QuerySortStrategy.none
public var queryItems: [URLQueryItem] {
let items = queryParameters.map {
URLQueryItem(name: $0, value: $1)
}
switch querySortStrategy {
case .none:
return items
case let .array(keys):
return items.sorted {
(keys.index(of: $0.name) ?? Int.max) < (keys.index(of: $1.name) ?? Int.max)
}
case let .callback(callback):
return items.sorted {
return callback($0.name, $1.name)
}
}
}
...
}
// tests
func testQuerySortStrategies() {
var path = self.path
// validate initial order assumption
XCTAssertEqual(path.queryItems.map { $0.name }, ["1", "11"])
// array strategry
path.querySortStrategy = .array(["11", "1"])
XCTAssertEqual(path.queryItems.map { $0.name }, ["11", "1"])
// closure strategy
path.querySortStrategy = .callback({
$0.count > $1.count
})
XCTAssertEqual(path.queryItems.map { $0.name }, ["11", "1"])
} |
It will solve the problem, but me myself, i'm not a fan of this way, since it is not error-prune. consider the cases when most of people forget to insert a Key inside |
Having a So .. This approach properly isolates the sorting strategy from the key/value pair definition. If a user forgets to give the proper order in their sorting strategy, they might make the same mistake in arranging them within an array, so it is a problem present in both cases. However, they might omit a key from the Hence, I think this solution is not ideal, but is also free from any major flaws. |
another possibly way is to allow an optional |
Well, I imported the |
Well, I remember we didn’t add Microsoft apps because they didn’t work with Appz. So, I have a suggestion if you don’t mind: I think the best thing to do is: to find a solution that works for both of this case and Microsoft apps. |
What's their problem? |
Please check #30 |
I know this is really stupid, but some apps, do not support QueryParameters like they should, and only support QueryItems in custom order. (like Maps.Me)
Any suggestions on how to fix this problem?
I was trying to add:
And use Query as an input, But since
Path
'squeryParameters
is variable and public, it'll definitely break backward compatibility.Any suggestions?
The text was updated successfully, but these errors were encountered: