From 6765033f96297508c603ff99c4ae56609fd22a58 Mon Sep 17 00:00:00 2001 From: Danny Sung Date: Mon, 23 Aug 2021 15:11:00 -0700 Subject: [PATCH] Update TravisCI: Remove Swift 4.x; Add Swift 5.4 (#61) * Update TravisCI: Remove Swift 4.x; Add Swift 5.4 * Swift 5.x update: Ensure RequestError body is not a JSON fragment * RequestError: JSON fragment enforcement in DEBUG builds only --- .travis.yml | 45 ++++--------------- KituraContracts.podspec | 2 +- Package@swift-4.0.swift | 28 ------------ Package@swift-4.1.swift | 28 ------------ Package@swift-4.2.swift | 28 ------------ Sources/KituraContracts/Contracts.swift | 9 +++- .../KituraContractsTests.swift | 4 +- 7 files changed, 21 insertions(+), 123 deletions(-) delete mode 100644 Package@swift-4.0.swift delete mode 100644 Package@swift-4.1.swift delete mode 100644 Package@swift-4.2.swift diff --git a/.travis.yml b/.travis.yml index 4395f27..007d1b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,55 +15,28 @@ matrix: dist: xenial sudo: required services: docker - env: DOCKER_IMAGE=swift:4.0.3 SWIFT_SNAPSHOT=4.0.3 + env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci-ubuntu16.04:5.1.5 - os: linux - dist: xenial - sudo: required - services: docker - env: DOCKER_IMAGE=swift:4.1.3 SWIFT_SNAPSHOT=4.1.3 - - os: linux - dist: xenial - sudo: required - services: docker - env: DOCKER_IMAGE=swift:4.2.4 SWIFT_SNAPSHOT=4.2.4 - - os: linux - dist: xenial - sudo: required - services: docker - env: DOCKER_IMAGE=swift:5.0.3-xenial SWIFT_SNAPSHOT=5.0.3 - - os: linux - dist: xenial + dist: bionic sudo: required services: docker - env: DOCKER_IMAGE=swift:5.1 + env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci-ubuntu18.04:5.4 - os: linux dist: xenial sudo: required services: docker - env: DOCKER_IMAGE=swift:5.1 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT - - os: osx - osx_image: xcode9.2 - sudo: required - env: SWIFT_SNAPSHOT=4.0.3 - - os: osx - osx_image: xcode9.4 - sudo: required - env: SWIFT_SNAPSHOT=4.1.2 + env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci-ubuntu18.04:latest USE_SWIFT_DEVELOPMENT_SNAPSHOT=1 - os: osx - osx_image: xcode10.1 + osx_image: xcode11 sudo: required - env: SWIFT_SNAPSHOT=4.2.1 + env: SWIFT_SNAPSHOT=5.1.5 JAZZY_ELIGIBLE=true - os: osx - osx_image: xcode10.2 + osx_image: xcode12.2 sudo: required - env: SWIFT_SNAPSHOT=5.0.1 JAZZY_ELIGIBLE=true - os: osx - osx_image: xcode11 - sudo: required - - os: osx - osx_image: xcode11 + osx_image: xcode12.5 sudo: required - env: SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT + env: USE_SWIFT_DEVELOPMENT_SNAPSHOT=1 before_install: - git clone https://github.com/Kitura/Package-Builder.git diff --git a/KituraContracts.podspec b/KituraContracts.podspec index 7fca2b5..e7f3419 100644 --- a/KituraContracts.podspec +++ b/KituraContracts.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "KituraContracts" - s.version = "1.2.200" + s.version = "2.0.0" s.summary = "KituraContracts is a library containing type definitions shared by client and server code." s.homepage = "https://github.com/Kitura/KituraContracts" s.license = { :type => "Apache License, Version 2.0" } diff --git a/Package@swift-4.0.swift b/Package@swift-4.0.swift deleted file mode 100644 index 90613c7..0000000 --- a/Package@swift-4.0.swift +++ /dev/null @@ -1,28 +0,0 @@ -// swift-tools-version:4.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "KituraContracts", - products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. - .library( - name: "KituraContracts", - targets: ["KituraContracts"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(url:"https://github.com/Kitura/LoggerAPI.git", from: "1.9.200"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target( - name: "KituraContracts", - dependencies: ["LoggerAPI"]), - .testTarget( - name: "KituraContractsTests", - dependencies: ["KituraContracts"]), - ] -) diff --git a/Package@swift-4.1.swift b/Package@swift-4.1.swift deleted file mode 100644 index 90613c7..0000000 --- a/Package@swift-4.1.swift +++ /dev/null @@ -1,28 +0,0 @@ -// swift-tools-version:4.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "KituraContracts", - products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. - .library( - name: "KituraContracts", - targets: ["KituraContracts"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(url:"https://github.com/Kitura/LoggerAPI.git", from: "1.9.200"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target( - name: "KituraContracts", - dependencies: ["LoggerAPI"]), - .testTarget( - name: "KituraContractsTests", - dependencies: ["KituraContracts"]), - ] -) diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift deleted file mode 100644 index 801efe2..0000000 --- a/Package@swift-4.2.swift +++ /dev/null @@ -1,28 +0,0 @@ -// swift-tools-version:4.2 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "KituraContracts", - products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. - .library( - name: "KituraContracts", - targets: ["KituraContracts"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(url:"https://github.com/Kitura/LoggerAPI.git", from: "1.9.200"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target( - name: "KituraContracts", - dependencies: ["LoggerAPI"]), - .testTarget( - name: "KituraContractsTests", - dependencies: ["KituraContracts"]), - ] -) diff --git a/Sources/KituraContracts/Contracts.swift b/Sources/KituraContracts/Contracts.swift index 067fce4..68bee4f 100644 --- a/Sources/KituraContracts/Contracts.swift +++ b/Sources/KituraContracts/Contracts.swift @@ -89,7 +89,14 @@ public struct RequestError: RawRepresentable, Equatable, Hashable, Comparable, E self.body = .codable(body) self.bodyDataEncoder = { format in switch format { - case .json: return try JSONEncoder().encode(body) + case .json: + let json = try JSONEncoder().encode(body) + + #if DEBUG + // ensure body is not a JSON fragment + _ = try JSONSerialization.jsonObject(with: json) + #endif + return json default: throw UnsupportedBodyFormatError(format) } } diff --git a/Tests/KituraContractsTests/KituraContractsTests.swift b/Tests/KituraContractsTests/KituraContractsTests.swift index 29f2854..4099790 100644 --- a/Tests/KituraContractsTests/KituraContractsTests.swift +++ b/Tests/KituraContractsTests/KituraContractsTests.swift @@ -215,7 +215,9 @@ class KituraContractsTests: XCTestCase { func testRequestErrorWithBodyThatCannotBeEncodedThrowsEncodingError() throws { let bogusBody = "Codable but not encodable to JSON" let error = RequestError(.serviceUnavailable, body: bogusBody) - XCTAssertThrowsError(try error.encodeBody(.json)) { XCTAssert($0 is EncodingError, "threw error: \($0)") } + XCTAssertThrowsError(try error.encodeBody(.json)) { + print("threw error: \($0)") + } } // Test construction of error instances with body data