Group Group Group Group Group Group Group Group Group

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")


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:

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:

•"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:

•"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