devxoul / MoyaSugar

🍯 Syntactic sugar for Moya
MIT License
192 stars 30 forks source link

MoyaSugar behaves differently when `route` contains an empty `path` #16

Closed lowip closed 7 years ago

lowip commented 7 years ago

I'm designing a simple SugarTargetType to download files from arbitrary urls:

/* ... */

var baseURL: URL {
  switch self {
  case .download(let url): return url
  }
}

var route: Route {
  return .get("")
}

/* ... */

Moya's previous behaviour was to always append the path to the baseURL. They changed this behaviour in Moya 8.0.4 (see: https://github.com/Moya/Moya/pull/1053) to avoid appending an extraneous / at the end of the url.

It seems to me that the code can easily be modified to respect the new Moya behaviour. The change would happen at https://github.com/devxoul/MoyaSugar/blob/master/Sources/SugarTargetType.swift#L56

var defaultURL: URL {
  return self.baseURL.appendingPathComponent(self.path)
}

would become

var defaultURL: URL {
  return self.path.isEmpty ? self.baseURL : self.baseURL.appendingPathComponent(self.path)
}

I would do a pull request but I am unable to compile the project on my computer.

devxoul commented 7 years ago

@lowip Thanks for reporting! #17 is a patch for this issue. I hope you could check this :)