Skip to content

Commit 785f3a8

Browse files
Improve init method signature
1 parent 28b1d32 commit 785f3a8

File tree

6 files changed

+233
-110
lines changed

6 files changed

+233
-110
lines changed

Sources/SwiftSlsAdapter/Function.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,32 @@ public struct Function: Codable, Equatable {
5959
image: String? = nil,
6060
runtime: Runtime?,
6161
memorySize: Int?,
62-
timeout: Int?,
63-
environment: YAMLContent?,
64-
ephemeralStorageSize: Int?,
65-
name: String?,
62+
timeout: Int? = nil,
63+
environment: YAMLContent? = nil,
64+
ephemeralStorageSize: Int? = nil,
65+
name: String? = nil,
6666
description: String,
67-
architecture: Architecture?,
68-
reservedConcurrency: Int?,
69-
provisionedConcurrency: Int?,
70-
role: String?,
71-
onError: String?,
72-
kmsKeyArn: String?,
73-
snapStart: Bool?,
74-
disableLogs: Bool?,
75-
logRetentionInDays: Int?,
76-
tags: [String: String]?,
77-
vpc: YAMLContent?,
78-
url: YAMLContent?,
67+
architecture: Architecture? = nil,
68+
reservedConcurrency: Int? = nil,
69+
provisionedConcurrency: Int? = nil,
70+
role: String? = nil,
71+
onError: String? = nil,
72+
kmsKeyArn: String? = nil,
73+
snapStart: Bool? = nil,
74+
disableLogs: Bool? = nil,
75+
logRetentionInDays: Int? = nil,
76+
tags: [String: String]? = nil,
77+
vpc: YAMLContent? = nil,
78+
url: YAMLContent? = nil,
7979
package: Package?,
8080
layers: YAMLContent?,
81-
tracing: Tracing?,
82-
condition: YAMLContent?,
83-
dependsOn: [String]?,
84-
destinations: YAMLContent?,
85-
fileSystemConfig: YAMLContent?,
86-
maximumRetryAttempts: Int?,
87-
maximumEventAge: Int?,
81+
tracing: Tracing? = nil,
82+
condition: YAMLContent? = nil,
83+
dependsOn: [String]? = nil,
84+
destinations: YAMLContent? = nil,
85+
fileSystemConfig: YAMLContent? = nil,
86+
maximumRetryAttempts: Int? = nil,
87+
maximumEventAge: Int? = nil,
8888
events: [FunctionEvent]
8989
) {
9090
self.handler = handler
@@ -264,7 +264,7 @@ public struct EventHTTPAPI: Codable, Equatable {
264264
public init(
265265
path: String,
266266
method: HTTPMethod,
267-
authorizer: YAMLContent?
267+
authorizer: YAMLContent? = nil
268268
) {
269269
self.path = path
270270
self.method = method

Sources/SwiftSlsAdapter/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct Package: Codable, Equatable {
2929
public init(
3030
patterns: [String]?,
3131
individually: Bool?,
32-
artifact: String?
32+
artifact: String? = nil
3333
) {
3434
self.patterns = patterns
3535
self.individually = individually

Sources/SwiftSlsAdapter/Provider.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ public struct Provider: Codable, Equatable {
4848
/// - iam: IAM permissions
4949
public init(
5050
name: Provider.CloudProvider,
51-
stage: Provider.Stage,
51+
stage: Provider.Stage? = nil,
5252
region: Region,
53-
profile: String?,
54-
tags: [String: String]?,
55-
stackName: String?,
56-
deploymentMethod: Provider.DeploymentMethod,
57-
notificationArns: [String]?,
58-
stackParameters: [Provider.StackParameters]?,
53+
profile: String? = nil,
54+
tags: [String: String]? = nil,
55+
stackName: String? = nil,
56+
deploymentMethod: Provider.DeploymentMethod = .changesets,
57+
notificationArns: [String]? = nil,
58+
stackParameters: [Provider.StackParameters]? = nil,
5959
disableRollback: Bool = false,
60-
rollbackConfiguration: Provider.RollbackConfiguration?,
60+
rollbackConfiguration: Provider.RollbackConfiguration? = nil,
6161
runtime: Runtime,
62-
memorySize: Int?,
63-
timeout: Int?,
62+
memorySize: Int? = nil,
63+
timeout: Int? = nil,
6464
environment: YAMLContent?,
65-
logRetentionInDays: Int?,
66-
logDataProtectionPolicy: YAMLContent?,
67-
kmsKeyArn: String?,
65+
logRetentionInDays: Int? = nil,
66+
logDataProtectionPolicy: YAMLContent? = nil,
67+
kmsKeyArn: String? = nil,
6868
lambdaHashingVersion: String,
6969
versionFunctions: Bool = true,
7070
architecture: Architecture,
@@ -102,7 +102,7 @@ public struct Provider: Codable, Equatable {
102102
public let name: CloudProvider
103103

104104
/// Default stage (default: dev)
105-
@CodableDefault.FirstCase public var stage: Stage
105+
public var stage: Stage?
106106

107107
/// Default region (default: us-east-1)
108108
@CodableDefault.FirstCase public var region: Region
@@ -316,13 +316,13 @@ extension Provider {
316316
/// - cors: Enable CORS HTTP headers with default settings (allow all)
317317
/// - authorizers: Authorizers
318318
public init(
319-
id: String?,
320-
name: String?,
319+
id: String? = nil,
320+
name: String? = nil,
321321
payload: String?,
322-
disableDefaultEndpoint: Bool?,
323-
metrics: Bool?,
322+
disableDefaultEndpoint: Bool? = nil,
323+
metrics: Bool? = nil,
324324
cors: Bool?,
325-
authorizers: Provider.Authorizers?
325+
authorizers: Provider.Authorizers? = nil
326326
) {
327327
self.id = id
328328
self.name = name
@@ -440,12 +440,12 @@ public struct Role: Codable, Equatable {
440440
/// - deploymentRole: ARN of an IAM role for CloudFormation service. If specified, CloudFormation uses the role's credentials
441441
public init(
442442
statements: [Statement],
443-
name: String?,
444-
path: String?,
445-
managedPolicies: [String]?,
446-
permissionsBoundary: String?,
447-
tags: [String: String]?,
448-
deploymentRole: String?
443+
name: String? = nil,
444+
path: String? = nil,
445+
managedPolicies: [String]? = nil,
446+
permissionsBoundary: String? = nil,
447+
tags: [String: String]? = nil,
448+
deploymentRole: String? = nil
449449
) {
450450
self.statements = statements
451451
self.name = name

Sources/SwiftSlsAdapter/Resource.swift

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,51 @@
1616

1717
import Foundation
1818

19-
// MARK: - ProductsTable
19+
public struct Resources {
20+
/// Build Resources
21+
/// - Parameter with: Resource dictionary
22+
/// - Returns: [String: AnyHashable]
23+
public static func resources(with dictionary: [String: [String: AnyHashable]]) -> [String: AnyHashable] {
24+
return ["Resources": dictionary]
25+
}
26+
}
2027

21-
/// Resource configuration
22-
public struct Resource: Codable {
23-
/// Initialise a Resource configuration
28+
/// Resource builder
29+
public struct Resource {
30+
/// Build a Resource
2431
///
2532
/// - Parameters:
26-
/// - type: Resource type
27-
/// - properties: Resource YAML properties
28-
public init(type: String, properties: YAMLContent) {
29-
self.type = type
30-
self.properties = properties
33+
/// - type: Type
34+
/// - properties: Properties
35+
/// - Returns: [String: AnyHashable]
36+
public static func resource(type: String, properties: [String: AnyHashable]) -> [String: AnyHashable] {
37+
return ["Type": type,
38+
"Properties": properties]
3139
}
32-
33-
/// Resource type
34-
public let type: String
3540

36-
/// Resource YAML properties
37-
public let properties: YAMLContent
38-
39-
enum CodingKeys: String, CodingKey {
40-
case type = "Type"
41-
case properties = "Properties"
42-
}
43-
}
44-
45-
extension Resource {
4641
/// Build a DynamoDB Resource with billing mode PAY_PER_REQUEST
4742
///
4843
/// - Parameters:
4944
/// - tableName: DynamoDB table name
5045
/// - key: DynamoDB key
51-
/// - Returns: Resource
52-
public static func DynamoDBResorce(tableName: String, key: String) throws -> Resource {
53-
return Resource(
46+
/// - Returns: [String: AnyHashable]
47+
public static func dynamoDBResource(tableName: String, key: String) -> [String: AnyHashable] {
48+
return Resource.resource(
5449
type: "AWS::DynamoDB::Table",
55-
properties: try YAMLContent.DynamoDBProperties(tableName: tableName, key: key)
50+
properties: Resource.dynamoDBProperties(tableName: tableName, key: key)
5651
)
5752
}
58-
}
5953

60-
extension YAMLContent {
6154
/// DynamoDB YAML properties
6255
///
6356
/// Billing mode PAY_PER_REQUEST
6457
/// see: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BillingModeSummary.html
6558
/// - Parameters:
6659
/// - tableName: DynamoDB table name
6760
/// - key: DynamoDB key name
68-
/// - Returns: YAMLContent
69-
public static func DynamoDBProperties(tableName: String, key: String) throws -> YAMLContent {
70-
let properties: [String: AnyHashable] = [
61+
/// - Returns: [String: AnyHashable]
62+
public static func dynamoDBProperties(tableName: String, key: String) -> [String: AnyHashable] {
63+
return [
7164
"TableName": tableName,
7265
"AttributeDefinitions": [
7366
"AttributeName": key,
@@ -79,6 +72,5 @@ extension YAMLContent {
7972
],
8073
"BillingMode": "PAY_PER_REQUEST"
8174
]
82-
return try YAMLContent(with: properties)
8375
}
8476
}

Sources/SwiftSlsAdapter/ServerlessConfig.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public struct ServerlessConfig: Codable, Equatable {
2828
///
2929
/// - Parameters:
3030
/// - service: Service Name
31+
/// - variablesResolutionMode: Variable resolution mode (default: 20210326)
3132
/// - frameworkVersion: Framework Version
3233
/// - configValidationMode: Configuration validation: 'error' (fatal error), 'warn' (logged to the output) or 'off' (default: warn)
3334
/// - useDotenv: Load environment variables from .env files (default: false)
@@ -39,6 +40,7 @@ public struct ServerlessConfig: Codable, Equatable {
3940
/// - resources: YAML Resources
4041
public init(
4142
service: String,
43+
variablesResolutionMode: String = "20210326",
4244
frameworkVersion: String = "3",
4345
configValidationMode: ServerlessConfig.ValidationMode = .warn,
4446
useDotenv: Bool = false,
@@ -50,6 +52,7 @@ public struct ServerlessConfig: Codable, Equatable {
5052
resources: YAMLContent?
5153
) {
5254
self.service = service
55+
self.variablesResolutionMode = variablesResolutionMode
5356
self.frameworkVersion = frameworkVersion
5457
self.configValidationMode = configValidationMode
5558
self.useDotenv = useDotenv
@@ -63,6 +66,9 @@ public struct ServerlessConfig: Codable, Equatable {
6366

6467
/// Service name
6568
public let service: String
69+
70+
/// Variable Resolution Mode
71+
public let variablesResolutionMode: String
6672

6773
/// Framework version constraint (semver constraint): '3', '^2.33'
6874
public let frameworkVersion: String

0 commit comments

Comments
 (0)