Skip to content

Commit

Permalink
Update TravisCI: Remove Swift 4.x; Add Swift 5.4 (#61)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dannys42 authored Aug 23, 2021
1 parent 025968b commit 6765033
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 123 deletions.
45 changes: 9 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion KituraContracts.podspec
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
28 changes: 0 additions & 28 deletions Package@swift-4.0.swift

This file was deleted.

28 changes: 0 additions & 28 deletions Package@swift-4.1.swift

This file was deleted.

28 changes: 0 additions & 28 deletions Package@swift-4.2.swift

This file was deleted.

9 changes: 8 additions & 1 deletion Sources/KituraContracts/Contracts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/KituraContractsTests/KituraContractsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6765033

Please sign in to comment.