Skip to content

Commit e451a2f

Browse files
committed
Minor updates
1 parent b20d95c commit e451a2f

File tree

4 files changed

+41
-60
lines changed

4 files changed

+41
-60
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
version:
1212
- 5.2.5
1313
- 5.3.3
14-
- nightly-5.4
14+
- 5.4
1515
- nightly
1616
container:
1717
image: stevapple/swift-scf:${{ matrix.version }}
@@ -42,6 +42,7 @@ jobs:
4242
version:
4343
- 5.2.5
4444
- 5.3.3
45+
- 5.4
4546
container:
4647
image: swift:${{ matrix.version }}-${{ matrix.os }}
4748
steps:
@@ -70,7 +71,6 @@ jobs:
7071
- centos8
7172
version:
7273
- nightly
73-
- nightly-5.4
7474
container:
7575
image: swiftlang/swift:${{ matrix.version }}-${{ matrix.os }}
7676
steps:

Sources/TencentSCFEvents/APIGateway/APIGateway.swift renamed to Sources/TencentSCFEvents/APIGateway.swift

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftTencentSCFRuntime open source project
44
//
5-
// Copyright (c) 2020 stevapple and the SwiftTencentSCFRuntime project authors
5+
// Copyright (c) 2020-2021 stevapple and the SwiftTencentSCFRuntime project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -19,7 +19,7 @@ import class Foundation.JSONEncoder
1919

2020
public enum APIGateway {
2121
/// `APIGateway.Request` contains data coming from the API Gateway.
22-
public struct Request<T: Decodable> {
22+
public struct Request<T: Decodable>: Decodable {
2323
public struct Context: Decodable {
2424
public let identity: [String: String]
2525
public let serviceId: String
@@ -40,6 +40,43 @@ public enum APIGateway {
4040

4141
public let context: Context
4242
public let body: T?
43+
44+
enum CodingKeys: String, CodingKey {
45+
case context = "requestContext"
46+
case body
47+
case headers
48+
case query = "queryString"
49+
case path
50+
case httpMethod
51+
52+
case pathParameters
53+
case queryStringParameters
54+
case headerParameters
55+
}
56+
57+
public init(from decoder: Decoder) throws {
58+
let container = try decoder.container(keyedBy: CodingKeys.self)
59+
60+
context = try container.decode(Context.self, forKey: .context)
61+
headers = try container.decode(HTTPHeaders.self, forKey: .headers)
62+
path = try container.decode(String.self, forKey: .path)
63+
httpMethod = try container.decode(HTTPMethod.self, forKey: .httpMethod)
64+
query = try container.decode([String: String].self, forKey: .query)
65+
pathParameters = try container.decode([String: String].self, forKey: .pathParameters)
66+
queryStringParameters = try container.decode([String: String].self, forKey: .queryStringParameters)
67+
headerParameters = try container.decode([String: String].self, forKey: .headerParameters)
68+
69+
do {
70+
body = try container.decodeIfPresent(T.self, forKey: .body)
71+
} catch {
72+
let bodyJson = try container.decodeIfPresent(String.self, forKey: .body)
73+
if let data = bodyJson?.data(using: .utf8) {
74+
body = try APIGateway.defaultJSONDecoder.decode(T.self, from: data)
75+
} else {
76+
body = nil
77+
}
78+
}
79+
}
4380
}
4481

4582
public enum Stage: String, Decodable {

Sources/TencentSCFEvents/APIGateway/Request+Decodable.swift

Lines changed: 0 additions & 54 deletions
This file was deleted.

Sources/TencentSCFEvents/APIResponse.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ public struct APIResponse: Encodable {
2121
public let headers: HTTPHeaders
2222
public let body: String
2323
public let isBase64Encoded: Bool
24-
}
2524

26-
extension APIResponse {
2725
public init(
2826
statusCode: HTTPResponseStatus,
2927
headers: HTTPHeaders = [:],

0 commit comments

Comments
 (0)