diff --git a/.gitignore b/.gitignore index 412279e..cb694f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ build .DS_Store .build/ -.swiftpm/ *.xcodeproj +.swift-version +.swiftpm/ *~ +.vscode/ diff --git a/Package.resolved b/Package.resolved index bc54db2..9ca1f49 100644 --- a/Package.resolved +++ b/Package.resolved @@ -14,18 +14,18 @@ "package": "ServiceModelSwiftCodeGenerate", "repositoryURL": "https://github.com/amzn/service-model-swift-code-generate.git", "state": { - "branch": null, - "revision": "286181816fccc2b6ec92049ba68426d08cbe0059", - "version": "3.0.0-beta.1" + "branch": "main", + "revision": "4c0ccda7df61c87538df34fc47982435c4a52206", + "version": null } }, { "package": "SmokeAWSGenerate", "repositoryURL": "https://github.com/amzn/smoke-aws-generate.git", "state": { - "branch": null, - "revision": "2d2902403408d4c7a9f6c69c90975cc048759f95", - "version": "3.0.0-beta.1" + "branch": "main", + "revision": "4a4a01557c23cd5d205ee0202be75587d48635c8", + "version": null } }, { diff --git a/Package.swift b/Package.swift index 25abcc5..1031742 100644 --- a/Package.swift +++ b/Package.swift @@ -38,8 +38,8 @@ let package = Package( targets: ["SmokeFrameworkGenerateHttp1"]), ], dependencies: [ - .package(url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-beta.1"), - .package(url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-beta.1"), + .package(url: "https://github.com/amzn/smoke-aws-generate.git", branch: "main"), + .package(url: "https://github.com/amzn/service-model-swift-code-generate.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), ], targets: [ diff --git a/Package@swift-5.4.swift b/Package@swift-5.4.swift index e56153b..faa3de5 100644 --- a/Package@swift-5.4.swift +++ b/Package@swift-5.4.swift @@ -30,9 +30,9 @@ let package = Package( ], dependencies: [ .package(name: "SmokeAWSGenerate", - url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/smoke-aws-generate.git", .branch("main")), .package(name: "ServiceModelSwiftCodeGenerate", - url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/service-model-swift-code-generate.git", .branch("main")), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), ], targets: [ diff --git a/Package@swift-5.5.swift b/Package@swift-5.5.swift index e56153b..faa3de5 100644 --- a/Package@swift-5.5.swift +++ b/Package@swift-5.5.swift @@ -30,9 +30,9 @@ let package = Package( ], dependencies: [ .package(name: "SmokeAWSGenerate", - url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/smoke-aws-generate.git", .branch("main")), .package(name: "ServiceModelSwiftCodeGenerate", - url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/service-model-swift-code-generate.git", .branch("main")), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), ], targets: [ diff --git a/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift b/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift index 41105da..c17e1ea 100644 --- a/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift +++ b/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift @@ -38,5 +38,9 @@ struct SmokeFrameworkCodeGen: Codable { let initializationType: InitializationType? let testDiscovery: CodeGenFeatureStatus? let mainAnnotation: CodeGenFeatureStatus? + let addSendableConformance: CodeGenFeatureStatus? + let eventLoopFutureClientAPIs: CodeGenFeatureStatus? + let minimumCompilerSupport: MinimumCompilerSupport? + let clientConfigurationType: ClientConfigurationType? let operationStubGenerationRule: OperationStubGenerationRule } diff --git a/Sources/SmokeFrameworkApplicationGenerate/main.swift b/Sources/SmokeFrameworkApplicationGenerate/main.swift index fefa746..30616da 100644 --- a/Sources/SmokeFrameworkApplicationGenerate/main.swift +++ b/Sources/SmokeFrameworkApplicationGenerate/main.swift @@ -47,6 +47,10 @@ struct Parameters { var initializationType: InitializationType? var testDiscovery: CodeGenFeatureStatus? var mainAnnotation: CodeGenFeatureStatus? + var addSendableConformance: CodeGenFeatureStatus? + var eventLoopFutureClientAPIs: CodeGenFeatureStatus? + var minimumCompilerSupport: MinimumCompilerSupport? + var clientConfigurationType: ClientConfigurationType? var operationStubGenerationRule: OperationStubGenerationRule } @@ -97,6 +101,10 @@ private func startCodeGeneration( initializationType: InitializationType, testDiscovery: CodeGenFeatureStatus, mainAnnotation: CodeGenFeatureStatus, + addSendableConformance: CodeGenFeatureStatus, + eventLoopFutureClientAPIs: CodeGenFeatureStatus, + minimumCompilerSupport: MinimumCompilerSupport, + clientConfigurationType: ClientConfigurationType, operationStubGenerationRule: OperationStubGenerationRule, modelOverride: ModelOverride?) throws -> ServiceModel { let validationErrorDeclaration = ErrorDeclaration.external( @@ -107,6 +115,10 @@ private func startCodeGeneration( validationErrorDeclaration: validationErrorDeclaration, unrecognizedErrorDeclaration: unrecognizedErrorDeclaration, asyncAwaitAPIs: asyncAwait.clientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + addSendableConformance: addSendableConformance, + minimumCompilerSupport: minimumCompilerSupport, + clientConfigurationType: clientConfigurationType, generateModelShapeConversions: true, optionalsInitializeEmpty: true, fileHeader: nil, @@ -203,6 +215,10 @@ func handleApplication(parameters: Parameters) throws { initializationType: parameters.initializationType ?? .original, testDiscovery: parameters.testDiscovery ?? .disabled, mainAnnotation: parameters.mainAnnotation ?? .disabled, + addSendableConformance: parameters.addSendableConformance ?? .disabled, + eventLoopFutureClientAPIs: parameters.eventLoopFutureClientAPIs ?? .enabled, + minimumCompilerSupport: parameters.minimumCompilerSupport ?? .unknown, + clientConfigurationType: parameters.clientConfigurationType ?? .generator, operationStubGenerationRule: parameters.operationStubGenerationRule, modelOverride: modelOverride) @@ -233,6 +249,10 @@ func handleApplication(parameters: Parameters) throws { initializationType: parameters.initializationType, testDiscovery: parameters.testDiscovery, mainAnnotation: parameters.mainAnnotation, + addSendableConformance: parameters.addSendableConformance, + eventLoopFutureClientAPIs: parameters.eventLoopFutureClientAPIs, + minimumCompilerSupport: parameters.minimumCompilerSupport, + clientConfigurationType: parameters.clientConfigurationType, operationStubGenerationRule: .allFunctionsWithinContextExceptStandaloneFunctionsFor(existingOperations.sorted(by: <))) let jsonEncoder = JSONEncoder() @@ -418,6 +438,10 @@ struct SmokeFrameworkApplicationGenerateCommand: ParsableCommand { initializationType: config?.initializationType, testDiscovery: config?.testDiscovery, mainAnnotation: config?.mainAnnotation, + addSendableConformance: config?.addSendableConformance, + eventLoopFutureClientAPIs: config?.eventLoopFutureClientAPIs, + minimumCompilerSupport: config?.minimumCompilerSupport, + clientConfigurationType: config?.clientConfigurationType, operationStubGenerationRule: operationStubGenerationRule) try handleApplication(parameters: parameters) diff --git a/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift b/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift index fb4857c..3406b19 100644 --- a/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift +++ b/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift @@ -37,6 +37,15 @@ extension ServiceModelCodeGenerator { } } + var conformingProtocols: [String] = [] + var conformancePadding: String = "" + if case .enabled = self.customizations.addSendableConformance { + conformingProtocols.append("Sendable") + conformancePadding = " " + } + + let conformingProtocolsString = conformingProtocols.joined(separator: ", ") + fileBuilder.appendLine(""" // // \(baseName)OperationsContext.swift @@ -49,7 +58,7 @@ extension ServiceModelCodeGenerator { /** The context to be passed to each of the \(baseName) operations. */ - public struct \(baseName)OperationsContext { + public struct \(baseName)OperationsContext \(conformingProtocolsString)\(conformancePadding){ let logger: Logger // TODO: Add properties to be accessed by the operation handlers diff --git a/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift b/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift index d5ee8f6..85aefd7 100644 --- a/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift +++ b/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift @@ -167,6 +167,9 @@ public struct SmokeFrameworkCodeGeneration { serviceModel: ModelType) throws { try codeGenerator.generateFromModel(serviceModel: serviceModel, generationType: generationType, asyncAwaitClientAPIs: customizations.asyncAwaitAPIs, + eventLoopFutureClientAPIs: customizations.eventLoopFutureClientAPIs, + minimumCompilerSupport: customizations.minimumCompilerSupport, + clientConfigurationType: customizations.clientConfigurationType, initializationType: initializationType, testDiscovery: testDiscovery, mainAnnotation: mainAnnotation, @@ -190,6 +193,9 @@ extension ServiceModelCodeGenerator { func generateFromModel(serviceModel: ModelType, generationType: GenerationType, asyncAwaitClientAPIs: CodeGenFeatureStatus, + eventLoopFutureClientAPIs: CodeGenFeatureStatus, + minimumCompilerSupport: MinimumCompilerSupport, + clientConfigurationType: ClientConfigurationType, initializationType: InitializationType, testDiscovery: CodeGenFeatureStatus, mainAnnotation: CodeGenFeatureStatus, @@ -199,17 +205,26 @@ extension ServiceModelCodeGenerator { eventLoopFutureOperationHandlers: CodeGenFeatureStatus) throws { let clientProtocolDelegate = ClientProtocolDelegate( baseName: applicationDescription.baseName, - asyncAwaitAPIs: asyncAwaitClientAPIs) + asyncAwaitAPIs: asyncAwaitClientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport) let mockClientDelegate = MockClientDelegate( baseName: applicationDescription.baseName, isThrowingMock: false, - asyncAwaitAPIs: asyncAwaitClientAPIs) + asyncAwaitAPIs: asyncAwaitClientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport) let throwingClientDelegate = MockClientDelegate( baseName: applicationDescription.baseName, isThrowingMock: true, - asyncAwaitAPIs: asyncAwaitClientAPIs) + asyncAwaitAPIs: asyncAwaitClientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport) let awsClientDelegate = APIGatewayClientDelegate( baseName: applicationDescription.baseName, asyncAwaitAPIs: asyncAwaitClientAPIs, + addSendableConformance: customizations.addSendableConformance, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport, contentType: "application/json", signAllHeaders: false, defaultInvocationTraceContext: InvocationTraceContextDeclaration(name: "SmokeInvocationTraceContext", importPackage: "SmokeOperationsHTTP1")) let awsModelErrorsDelegate = SmokeFrameworkModelErrorsDelegate() @@ -230,11 +245,19 @@ extension ServiceModelCodeGenerator { } if generationType.needsClient { - generateClient(delegate: clientProtocolDelegate, isGenerator: false) - generateClient(delegate: mockClientDelegate, isGenerator: false) - generateClient(delegate: throwingClientDelegate, isGenerator: false) - generateClient(delegate: awsClientDelegate, isGenerator: false) - generateClient(delegate: awsClientDelegate, isGenerator: true) + let generatorFileType: ClientFileType + switch clientConfigurationType { + case .configurationObject: + generatorFileType = .clientConfiguration + case .generator: + generatorFileType = .clientGenerator + } + + generateClient(delegate: clientProtocolDelegate, fileType: .clientImplementation) + generateClient(delegate: mockClientDelegate, fileType: .clientImplementation) + generateClient(delegate: throwingClientDelegate, fileType: .clientImplementation) + generateClient(delegate: awsClientDelegate, fileType: .clientImplementation) + generateClient(delegate: awsClientDelegate, fileType: generatorFileType) generateOperationsReporting() generateInvocationsReporting() generateModelOperationClientInput()