Skip to content

Commit

Permalink
Conform Bool to Content (#2848)
Browse files Browse the repository at this point in the history
* Add bool to support content protocol by default

Add bool to support the content protocol by default. You can directly return bool types at the top level.

````swift
    app.get("isOK") { req in
        return true
    }
``

* New test bool supports content protocol

Co-authored-by: king <3925@winnermedical.com>
  • Loading branch information
josercc and josercc committed Jun 15, 2022
1 parent 6c63226 commit 12e2e74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Vapor/Content/Content.swift
Expand Up @@ -111,6 +111,8 @@ extension UInt16: Content { }
extension UInt32: Content { }
extension UInt64: Content { }

extension Bool: Content {}

extension BinaryFloatingPoint where Self: Content {
public static var defaultContentType: HTTPMediaType {
return .plainText
Expand Down
13 changes: 13 additions & 0 deletions Tests/VaporTests/ContentTests.swift
Expand Up @@ -489,6 +489,19 @@ final class ContentTests: XCTestCase {
XCTAssertEqual(res.status, .badRequest)
}
}

func testContentIsBool() throws {
let app = Application(.testing)
defer { app.shutdown() }

app.routes.get("success") { req in
return true
}

try app.testable().test(.GET, "/success") { res in
XCTAssertEqual(try res.content.decode(Bool.self), true)
}
}
}

private struct SampleContent: Content {
Expand Down

0 comments on commit 12e2e74

Please sign in to comment.