From 6d6a1347e521ea6f12e19a7282ac018e7116c33c Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Tue, 22 Nov 2022 07:36:54 +1100 Subject: [PATCH 1/2] Associate an OverridesType with a ServiceModel type. --- Package.swift | 6 +-- .../SmokeFrameworkCodeGen.swift | 2 +- .../main.swift | 28 +++++++------- ...delClientDelegate+commonAWSFunctions.swift | 8 ++-- .../SmokeFrameworkCodeGeneration.swift | 38 +++++++++---------- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/Package.swift b/Package.swift index 539da01..8bd1cac 100644 --- a/Package.swift +++ b/Package.swift @@ -38,9 +38,9 @@ let package = Package( targets: ["SmokeFrameworkGenerateHttp1"]), ], dependencies: [ - .package(url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-rc.1"), - .package(url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-rc.1"), - .package(url: "https://github.com/amzn/openapi-swift-code-generate.git", from: "1.0.0-beta.1"), + .package(url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-rc.6"), + .package(url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-rc.2"), + .package(url: "https://github.com/amzn/openapi-swift-code-generate.git", from: "1.0.0-rc.1"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), ], targets: [ diff --git a/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift b/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift index aebe32d..7cb6dda 100644 --- a/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift +++ b/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift @@ -32,7 +32,7 @@ struct SmokeFrameworkCodeGen: Codable { let generationType: GenerationType let integrations: ServiceIntegrations? let applicationDescription: String? - let modelOverride: ModelOverride? + let modelOverride: ModelOverride? let httpClientConfiguration: HttpClientConfiguration? let asyncAwait: AsyncAwaitCodeGenParameters? let eventLoopFutureOperationHandlers: CodeGenFeatureStatus? diff --git a/Sources/SmokeFrameworkApplicationGenerate/main.swift b/Sources/SmokeFrameworkApplicationGenerate/main.swift index 82f408c..198d2e6 100644 --- a/Sources/SmokeFrameworkApplicationGenerate/main.swift +++ b/Sources/SmokeFrameworkApplicationGenerate/main.swift @@ -40,7 +40,7 @@ struct Parameters { var generationType: GenerationType var integrations: ServiceIntegrations? var applicationDescription: String? - var modelOverride: ConfigurationProvider? + var modelOverride: ConfigurationProvider>? var generateCodeGenConfig: Bool? var httpClientConfiguration: ConfigurationProvider? var asyncAwait: AsyncAwaitCodeGenParameters? @@ -55,8 +55,8 @@ struct Parameters { var operationStubGenerationRule: OperationStubGenerationRule } -private func getModelOverride(modelOverridePath: String?) throws -> ModelOverride? { - let modelOverride: ModelOverride? +private func getModelOverride(modelOverridePath: String?) throws -> ModelOverride? { + let modelOverride: ModelOverride? if let modelOverridePath = modelOverridePath { let overrideFile = FileHandle(forReadingAtPath: modelOverridePath) @@ -64,7 +64,7 @@ private func getModelOverride(modelOverridePath: String?) throws -> ModelOverrid fatalError("Specified model file '\(modelOverridePath)' doesn't exist.") } - modelOverride = try JSONDecoder().decode(ModelOverride.self, from: overrideData) + modelOverride = try JSONDecoder().decode(ModelOverride.self, from: overrideData) } else { modelOverride = nil } @@ -108,7 +108,7 @@ private func startCodeGeneration( minimumCompilerSupport: MinimumCompilerSupport, clientConfigurationType: ClientConfigurationType, operationStubGenerationRule: OperationStubGenerationRule, - modelOverride: ModelOverride?) throws -> ServiceModel { + modelOverride: ModelOverride?) throws -> [String] { let validationErrorDeclaration = ErrorDeclaration.external( libraryImport: "SmokeOperations", errorType: "SmokeOperationsError") @@ -138,7 +138,7 @@ private func startCodeGeneration( switch modelFormat { case .openAPI30: - return try SmokeFrameworkCodeGeneration.generateFromModel( + let model = try SmokeFrameworkCodeGeneration.generateFromModel( modelFilePath: modelFilePath, modelType: OpenAPIServiceModel.self, generationType: generationType, @@ -154,8 +154,10 @@ private func startCodeGeneration( mainAnnotation: mainAnnotation, asyncInitialization: asyncAwait.asyncInitialization ?? .disabled, modelOverride: modelOverride) + + return Array(model.operationDescriptions.keys) case .swagger: - return try SmokeFrameworkCodeGeneration.generateFromModel( + let model = try SmokeFrameworkCodeGeneration.generateFromModel( modelFilePath: modelFilePath, modelType: SwaggerServiceModel.self, generationType: generationType, @@ -171,11 +173,13 @@ private func startCodeGeneration( mainAnnotation: mainAnnotation, asyncInitialization: asyncAwait.asyncInitialization ?? .disabled, modelOverride: modelOverride) + + return Array(model.operationDescriptions.keys) } } func handleApplication(parameters: Parameters) throws { - let modelOverride: ModelOverride? + let modelOverride: ModelOverride? switch parameters.modelOverride { case .provided(let provided): modelOverride = provided @@ -212,7 +216,7 @@ func handleApplication(parameters: Parameters) throws { applicationDescription = "The \(parameters.baseName)\(applicationSuffix)." } - let model = try startCodeGeneration( + let existingOperations = try startCodeGeneration( httpClientConfiguration: httpClientConfiguration, baseName: parameters.baseName, baseFilePath: parameters.baseOutputFilePath ?? parameters.baseFilePath, @@ -245,9 +249,7 @@ func handleApplication(parameters: Parameters) throws { } else { modelFilePath = parameterModelFilePath } - - let existingOperations = Array(model.operationDescriptions.keys) - + let smokeFrameworkCodeGen = SmokeFrameworkCodeGen(modelFilePath: modelFilePath, modelFormat: parameters.modelFormat, baseName: parameters.baseName, applicationSuffix: parameters.applicationSuffix, @@ -399,7 +401,7 @@ struct SmokeFrameworkApplicationGenerateCommand: ParsableCommand { theApplicationDescription = nil } - let modelOverride: ConfigurationProvider? + let modelOverride: ConfigurationProvider>? if let modelOverridePath = modelOverridePath { modelOverride = .atPath(modelOverridePath) } else if let modelOverrideFromConfig = config?.modelOverride { diff --git a/Sources/SmokeFrameworkCodeGeneration/ModelClientDelegate+commonAWSFunctions.swift b/Sources/SmokeFrameworkCodeGeneration/ModelClientDelegate+commonAWSFunctions.swift index 3b9c5d3..5e6a241 100644 --- a/Sources/SmokeFrameworkCodeGeneration/ModelClientDelegate+commonAWSFunctions.swift +++ b/Sources/SmokeFrameworkCodeGeneration/ModelClientDelegate+commonAWSFunctions.swift @@ -92,7 +92,8 @@ extension ModelClientDelegate { } private func addInstanceVariables(isQuery: Bool, httpClientConfiguration: HttpClientConfiguration, - codeGenerator: ServiceModelCodeGenerator, clientAttributes: AWSClientAttributes, + codeGenerator: ServiceModelCodeGenerator, + clientAttributes: AWSClientAttributes, targetsAPIGateway: Bool, targetValue: String, fileBuilder: FileBuilder) -> HttpClientSignatureParameters { let targetOrVersionParameter: String let targetAssignment: String @@ -164,7 +165,8 @@ extension ModelClientDelegate { } fileprivate func addInitializerBody(httpClientConfiguration: HttpClientConfiguration, isQuery: Bool, baseName: String, - codeGenerator: ServiceModelCodeGenerator, regionAssignmentPostfix: String, + codeGenerator: ServiceModelCodeGenerator, + regionAssignmentPostfix: String, signatureParameters: HttpClientSignatureParameters, targetsAPIGateway: Bool, fileBuilder: FileBuilder) { addDelegateForHttpClient(httpClientConfiguration: httpClientConfiguration, isQuery: isQuery, baseName: baseName, fileBuilder: fileBuilder) @@ -213,7 +215,7 @@ extension ModelClientDelegate { func addAWSClientCommonFunctions(fileBuilder: FileBuilder, baseName: String, clientAttributes: AWSClientAttributes, - codeGenerator: ServiceModelCodeGenerator, + codeGenerator: ServiceModelCodeGenerator, targetsAPIGateway: Bool, isQuery: Bool) { let targetValue: String diff --git a/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift b/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift index 715280b..4ce8589 100644 --- a/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift +++ b/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift @@ -172,7 +172,7 @@ public struct SmokeFrameworkCodeGeneration { testDiscovery: CodeGenFeatureStatus, mainAnnotation: CodeGenFeatureStatus, asyncInitialization: CodeGenFeatureStatus, - modelOverride: ModelOverride?) throws + modelOverride: ModelOverride?) throws -> ModelType { let targetSupport = SmokeFrameworkTargetSupport(modelTargetName: modelTargetName, clientTargetName: clientTargetName, http1IntegrationTargetName: http1IntegrationTargetName) @@ -219,38 +219,38 @@ public struct SmokeFrameworkTargetSupport: ModelTargetSupport, ClientTargetSuppo extension ServiceModelCodeGenerator where TargetSupportType: ModelTargetSupport & ClientTargetSupport & HTTP1IntegrationTargetSupport { - func generateFromModel(serviceModel: ModelType, - generationType: GenerationType, - integrations: ServiceIntegrations?, - asyncAwaitClientAPIs: CodeGenFeatureStatus, - eventLoopFutureClientAPIs: CodeGenFeatureStatus, - minimumCompilerSupport: MinimumCompilerSupport, - clientConfigurationType: ClientConfigurationType, - initializationType: InitializationType, - testDiscovery: CodeGenFeatureStatus, - mainAnnotation: CodeGenFeatureStatus, - asyncInitialization: CodeGenFeatureStatus, - operationStubGenerationRule: OperationStubGenerationRule, - asyncOperationStubs: CodeGenFeatureStatus, - eventLoopFutureOperationHandlers: CodeGenFeatureStatus) throws { - let clientProtocolDelegate = ClientProtocolDelegate( + func generateFromModel(serviceModel: ModelType, + generationType: GenerationType, + integrations: ServiceIntegrations?, + asyncAwaitClientAPIs: CodeGenFeatureStatus, + eventLoopFutureClientAPIs: CodeGenFeatureStatus, + minimumCompilerSupport: MinimumCompilerSupport, + clientConfigurationType: ClientConfigurationType, + initializationType: InitializationType, + testDiscovery: CodeGenFeatureStatus, + mainAnnotation: CodeGenFeatureStatus, + asyncInitialization: CodeGenFeatureStatus, + operationStubGenerationRule: OperationStubGenerationRule, + asyncOperationStubs: CodeGenFeatureStatus, + eventLoopFutureOperationHandlers: CodeGenFeatureStatus) throws { + let clientProtocolDelegate = ClientProtocolDelegate( baseName: applicationDescription.baseName, asyncAwaitAPIs: asyncAwaitClientAPIs, eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, minimumCompilerSupport: minimumCompilerSupport) - let mockClientDelegate = MockClientDelegate( + let mockClientDelegate = MockClientDelegate( baseName: applicationDescription.baseName, isThrowingMock: false, asyncAwaitAPIs: asyncAwaitClientAPIs, eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, minimumCompilerSupport: minimumCompilerSupport) - let throwingClientDelegate = MockClientDelegate( + let throwingClientDelegate = MockClientDelegate( baseName: applicationDescription.baseName, isThrowingMock: true, asyncAwaitAPIs: asyncAwaitClientAPIs, eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, minimumCompilerSupport: minimumCompilerSupport) - let awsClientDelegate = APIGatewayClientDelegate( + let awsClientDelegate = APIGatewayClientDelegate( baseName: applicationDescription.baseName, asyncAwaitAPIs: asyncAwaitClientAPIs, addSendableConformance: customizations.addSendableConformance, eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, From 23c2642807bc5b0a31313258b61802f5a48bf0a9 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Tue, 22 Nov 2022 07:53:41 +1100 Subject: [PATCH 2/2] Fix 5.5. --- Package.resolved | 12 ++++++------ Package@swift-5.5.swift | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Package.resolved b/Package.resolved index 6807937..e2b8418 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/amzn/openapi-swift-code-generate.git", "state": { "branch": null, - "revision": "f724141e19f151197b283ffe05acd7fc691f66d0", - "version": "1.0.0-beta.1" + "revision": "4210a8db0c2dc1e78bae9e302165c448d2ee361e", + "version": "1.0.0-rc.1" } }, { @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/amzn/service-model-swift-code-generate.git", "state": { "branch": null, - "revision": "42c354dc16893d30d602bd24f8f570f20fc6206a", - "version": "3.0.0-rc.1" + "revision": "3cacd62f7290554185ffcf839ec75c4ee2584d8e", + "version": "3.0.0-rc.2" } }, { @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/amzn/smoke-aws-generate.git", "state": { "branch": null, - "revision": "8d2dcd6f7782cd76ff7c98aae58a6a515281f4d5", - "version": "3.0.0-rc.1" + "revision": "c091b7e08be0ba5c1f8c08c3a145796c6b800f36", + "version": "3.0.0-rc.6" } }, { diff --git a/Package@swift-5.5.swift b/Package@swift-5.5.swift index 466a600..d2a7e3d 100644 --- a/Package@swift-5.5.swift +++ b/Package@swift-5.5.swift @@ -30,10 +30,10 @@ let package = Package( ], dependencies: [ .package(name: "SmokeAWSGenerate", - url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-rc.1"), + url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-rc.6"), .package(name: "ServiceModelSwiftCodeGenerate", - url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-rc.1"), - .package(url: "https://github.com/amzn/openapi-swift-code-generate.git", from: "1.0.0-beta.1"), + url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-rc.2"), + .package(url: "https://github.com/amzn/openapi-swift-code-generate.git", from: "1.0.0-rc.1"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), ], targets: [