Errata for Server-Side Swift with Vapor 3rd Edition

Creating this topic to catch any typos and bugs in the 3rd Edition Edition of Server-Side Swift with Vapor.

I hit a snag in Chapter 19 where a couple of tests werenā€™t passing. Specifically the testUpdatingAnAcronym() and testAcronymCanBeSavedWithAPI() tests were failing.

I discovered that it was due to the default password not being encrypted in the User.create(name:username:on) extension method defined in Models+Testable.swift. To fix it I replaced this line:

let user = User(name: name, username: createUsername, password: "password")

with:

let user = User(name: name, username: createUsername, password: try Bcrypt.hash("password"))

I couldnā€™t find this change mentioned in the book (although I might have missed it). With this in place all tests are now :white_check_mark:.

@joltguy itā€™s in the very first block of code in Chapter 19 :slightly_smiling_face:

https://www.raywenderlich.com/books/server-side-swift-with-vapor/v3.0/chapters/19-api-authentication-part-2#toc-chapter-022-anchor-001

Dā€™oh!! :flushed:

I donā€™t know how I missed that! Itā€™s like I typed in most of that block but somehow skipped the bottom part. Gahā€¦ sorry about that. Thanks for pointing it out!

1 Like

In Chapter 17, there is a sentence that has multiple ā€œtoā€ which I think is a typo:
This is similar to to the existing CreateAcronymData in AcronymsController.swift .

Thanks! Iā€™ll get that fixed in the next update!

Hi Tim, I think that thereā€™s a small typo in Chapter 8. On p111 of the PDF.

It states

Open AcronymsController.swift in Xcode and add the following to create an AcronymsController that conforms to RouteCollection:

import Vapor
import Fluent
struct AcronymsController: RouteCollection {
  func boot(routes: RoutesBuilder) throws {
  } 
}

But then just over the page on p112 the next sentence states:

RouteCollection requires you to implement boot(router:) to register routes.

I assume that the ā€˜router:ā€™ parameter is a hang-over from v3 of Vapor, and that the sentence should read:

RouteCollection requires you to implement boot(routes:) to register routes.

Similarly, I think that thereā€™s some Vapor v3 code left in p114:

Next, open routes.swift and remove the remaining acronym route handlers:

ā€¢ router.post("api", "acronyms")
ā€¢ router.get("api", "acronyms", Acronym.parameter)
ā€¢ router.put("api", "acronyms", Acronym.parameter)
ā€¢ router.delete("api", "acronyms", Acronym.parameter) 
ā€¢ router.get("api", "acronyms", "search")
ā€¢ router.get("api", "acronyms", "first")
ā€¢ router.get("api", "acronyms", "sorted")

I suspect that should, instead, read:

ā€¢app.post("api", "acronyms")
ā€¢app.get("api", "acronyms", ":acronymID")
ā€¢app.put("api", "acronyms", ":acronymID")
ā€¢app.delete("api", "acronyms", ":acronymID")
ā€¢app.get("api", "acronyms", "search")
ā€¢app.get("api", "acronyms", "first")
ā€¢app.get("api", "acronyms", "sorted")

And just under that:

Next, remove any other routes from the template. You should only have the AcronymsController registration left in routes(_:). Next, open AcronymsController.swift and recreate the handlers by adding each of the following after boot(router:)

s/router:/routes: again.

Thanks for spotting these! I suspect there was an errant merge somewhere. The fix should get merged and deployed soon