Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate an OverridesType with a ServiceModel type. #40

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand All @@ -24,17 +24,17 @@
"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"
}
},
{
"package": "SmokeAWSGenerate",
"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"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
6 changes: 3 additions & 3 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct SmokeFrameworkCodeGen: Codable {
let generationType: GenerationType
let integrations: ServiceIntegrations?
let applicationDescription: String?
let modelOverride: ModelOverride?
let modelOverride: ModelOverride<NoModelTypeOverrides>?
let httpClientConfiguration: HttpClientConfiguration?
let asyncAwait: AsyncAwaitCodeGenParameters?
let eventLoopFutureOperationHandlers: CodeGenFeatureStatus?
Expand Down
28 changes: 15 additions & 13 deletions Sources/SmokeFrameworkApplicationGenerate/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Parameters {
var generationType: GenerationType
var integrations: ServiceIntegrations?
var applicationDescription: String?
var modelOverride: ConfigurationProvider<ModelOverride>?
var modelOverride: ConfigurationProvider<ModelOverride<NoModelTypeOverrides>>?
var generateCodeGenConfig: Bool?
var httpClientConfiguration: ConfigurationProvider<HttpClientConfiguration>?
var asyncAwait: AsyncAwaitCodeGenParameters?
Expand All @@ -55,16 +55,16 @@ struct Parameters {
var operationStubGenerationRule: OperationStubGenerationRule
}

private func getModelOverride(modelOverridePath: String?) throws -> ModelOverride? {
let modelOverride: ModelOverride?
private func getModelOverride(modelOverridePath: String?) throws -> ModelOverride<NoModelTypeOverrides>? {
let modelOverride: ModelOverride<NoModelTypeOverrides>?
if let modelOverridePath = modelOverridePath {
let overrideFile = FileHandle(forReadingAtPath: modelOverridePath)

guard let overrideData = overrideFile?.readDataToEndOfFile() else {
fatalError("Specified model file '\(modelOverridePath)' doesn't exist.")
}

modelOverride = try JSONDecoder().decode(ModelOverride.self, from: overrideData)
modelOverride = try JSONDecoder().decode(ModelOverride<NoModelTypeOverrides>.self, from: overrideData)
} else {
modelOverride = nil
}
Expand Down Expand Up @@ -108,7 +108,7 @@ private func startCodeGeneration(
minimumCompilerSupport: MinimumCompilerSupport,
clientConfigurationType: ClientConfigurationType,
operationStubGenerationRule: OperationStubGenerationRule,
modelOverride: ModelOverride?) throws -> ServiceModel {
modelOverride: ModelOverride<NoModelTypeOverrides>?) throws -> [String] {
let validationErrorDeclaration = ErrorDeclaration.external(
libraryImport: "SmokeOperations",
errorType: "SmokeOperationsError")
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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<NoModelTypeOverrides>?
switch parameters.modelOverride {
case .provided(let provided):
modelOverride = provided
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -399,7 +401,7 @@ struct SmokeFrameworkApplicationGenerateCommand: ParsableCommand {
theApplicationDescription = nil
}

let modelOverride: ConfigurationProvider<ModelOverride>?
let modelOverride: ConfigurationProvider<ModelOverride<NoModelTypeOverrides>>?
if let modelOverridePath = modelOverridePath {
modelOverride = .atPath(modelOverridePath)
} else if let modelOverrideFromConfig = config?.modelOverride {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ extension ModelClientDelegate {
}

private func addInstanceVariables(isQuery: Bool, httpClientConfiguration: HttpClientConfiguration,
codeGenerator: ServiceModelCodeGenerator<TargetSupportType>, clientAttributes: AWSClientAttributes,
codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
clientAttributes: AWSClientAttributes,
targetsAPIGateway: Bool, targetValue: String, fileBuilder: FileBuilder) -> HttpClientSignatureParameters {
let targetOrVersionParameter: String
let targetAssignment: String
Expand Down Expand Up @@ -164,7 +165,8 @@ extension ModelClientDelegate {
}

fileprivate func addInitializerBody(httpClientConfiguration: HttpClientConfiguration, isQuery: Bool, baseName: String,
codeGenerator: ServiceModelCodeGenerator<TargetSupportType>, regionAssignmentPostfix: String,
codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
regionAssignmentPostfix: String,
signatureParameters: HttpClientSignatureParameters, targetsAPIGateway: Bool, fileBuilder: FileBuilder) {
addDelegateForHttpClient(httpClientConfiguration: httpClientConfiguration, isQuery: isQuery,
baseName: baseName, fileBuilder: fileBuilder)
Expand Down Expand Up @@ -213,7 +215,7 @@ extension ModelClientDelegate {

func addAWSClientCommonFunctions(fileBuilder: FileBuilder, baseName: String,
clientAttributes: AWSClientAttributes,
codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
targetsAPIGateway: Bool,
isQuery: Bool) {
let targetValue: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public struct SmokeFrameworkCodeGeneration {
testDiscovery: CodeGenFeatureStatus,
mainAnnotation: CodeGenFeatureStatus,
asyncInitialization: CodeGenFeatureStatus,
modelOverride: ModelOverride?) throws
modelOverride: ModelOverride<ModelType.OverridesType>?) throws
-> ModelType {
let targetSupport = SmokeFrameworkTargetSupport(modelTargetName: modelTargetName, clientTargetName: clientTargetName,
http1IntegrationTargetName: http1IntegrationTargetName)
Expand Down Expand Up @@ -219,38 +219,38 @@ public struct SmokeFrameworkTargetSupport: ModelTargetSupport, ClientTargetSuppo

extension ServiceModelCodeGenerator where TargetSupportType: ModelTargetSupport & ClientTargetSupport & HTTP1IntegrationTargetSupport {

func generateFromModel<ModelType: ServiceModel>(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<TargetSupportType>(
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<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
asyncAwaitAPIs: asyncAwaitClientAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
minimumCompilerSupport: minimumCompilerSupport)
let mockClientDelegate = MockClientDelegate<TargetSupportType>(
let mockClientDelegate = MockClientDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
isThrowingMock: false,
asyncAwaitAPIs: asyncAwaitClientAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
minimumCompilerSupport: minimumCompilerSupport)
let throwingClientDelegate = MockClientDelegate<TargetSupportType>(
let throwingClientDelegate = MockClientDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
isThrowingMock: true,
asyncAwaitAPIs: asyncAwaitClientAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
minimumCompilerSupport: minimumCompilerSupport)
let awsClientDelegate = APIGatewayClientDelegate<TargetSupportType>(
let awsClientDelegate = APIGatewayClientDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName, asyncAwaitAPIs: asyncAwaitClientAPIs,
addSendableConformance: customizations.addSendableConformance,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
Expand Down