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

Add additional generator options. #34

Merged
merged 2 commits into from
Aug 11, 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build
.DS_Store
.build/
.swiftpm/
*.xcodeproj
.swift-version
.swiftpm/
*~
.vscode/
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 24 additions & 0 deletions Sources/SmokeFrameworkApplicationGenerate/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -190,6 +193,9 @@ extension ServiceModelCodeGenerator {
func generateFromModel<ModelType: ServiceModel>(serviceModel: ModelType,
generationType: GenerationType,
asyncAwaitClientAPIs: CodeGenFeatureStatus,
eventLoopFutureClientAPIs: CodeGenFeatureStatus,
minimumCompilerSupport: MinimumCompilerSupport,
clientConfigurationType: ClientConfigurationType,
initializationType: InitializationType,
testDiscovery: CodeGenFeatureStatus,
mainAnnotation: CodeGenFeatureStatus,
Expand All @@ -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()
Expand All @@ -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()
Expand Down