Vapor v4.22.0 Release Notes

Release Date: 2020-07-16 // almost 4 years ago
  • 🚀 ###### This patch was authored by @odanylewycz and released by @tanner0101.

    ➕ Adds validate(query:) method to Validatable protocol for validating decoded query parameters (#2419).

    Previously, you could only validate the content that came from the request body. Now, this addition allows for validating decoded query parameters that conform to the Content protocol.

    struct Hello: Content, Validatable { name: String?static func validations(\_ validations: inout Validations) { validations.add("name", as: String.self, is: .alphanumeric) } }
    

    And the following URL, http://localhost:8080/model?name=Vapor, you can now validate the query parameter "name" as follows:

    try Hello.validate(query: request)let hello = try req.query.decode(Hello.self)
    

    The existing content validation method validate(_:) has been renamed to validate(content:) to reduce ambiguity.

    try Hello.validate(content: request)let hello = try req.content.decode(Hello.self)