Skip to content

Commit

Permalink
Merge pull request #88 from amzn/model_type_specific_override_types
Browse files Browse the repository at this point in the history
Use model type specific ModelOverride types.
  • Loading branch information
tachyonics authored Nov 21, 2022
2 parents e1e1f75 + 3f189e8 commit c091b7e
Show file tree
Hide file tree
Showing 30 changed files with 77 additions and 76 deletions.
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,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"
}
},
{
Expand All @@ -42,8 +42,8 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser",
"state": {
"branch": null,
"revision": "9f39744e025c7d377987f30b03770805dcb0bcd1",
"version": "1.1.4"
"revision": "fddd1c00396eed152c45a46bea9f47b98e59301d",
"version": "1.2.0"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ let package = Package(
targets: ["APIGatewaySwiftGenerateClient"]),
],
dependencies: [
.package(url: "https://github.com/amzn/service-model-swift-code-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.2"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(url: "https://github.com/amzn/openapi-swift-code-generate.git", from: "1.0.0-beta.1"),
.package(url: "https://github.com/amzn/openapi-swift-code-generate.git", from: "1.0.0-rc.1"),
],
targets: [
.plugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum ModelFormat: String, Codable {
struct APIGatewayClientSwiftCodeGen: Decodable {
let modelFormat: ModelFormat?
let baseName: String
let modelOverride: ModelOverride?
let modelOverride: ModelOverride<NoModelTypeOverrides>?
let httpClientConfiguration: HttpClientConfiguration?
let shapeProtocols: CodeGenFeatureStatus?
let eventLoopFutureClientAPIs: CodeGenFeatureStatus?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct APIGatewayClientCodeGeneration {
modelTargetName: String, clientTargetName: String,
customizations: CodeGenerationCustomizations,
applicationDescription: ApplicationDescription,
modelOverride: ModelOverride?) throws
modelOverride: ModelOverride<ModelType.OverridesType>?) throws
-> ModelType {
let targetSupport = ModelAndClientTargetSupport(modelTargetName: modelTargetName,
clientTargetName: clientTargetName)
Expand All @@ -64,7 +64,7 @@ public struct APIGatewayClientCodeGeneration {
modelTargetName: String, clientTargetName: String,
customizations: CodeGenerationCustomizations,
applicationDescription: ApplicationDescription,
modelOverride: ModelOverride?) throws {
modelOverride: ModelOverride<ModelType.OverridesType>?) throws {
let targetSupport = ModelAndClientTargetSupport(modelTargetName: modelTargetName,
clientTargetName: clientTargetName)

Expand All @@ -90,7 +90,7 @@ public struct APIGatewayClientCodeGeneration {
modelTargetName: String, clientTargetName: String,
customizations: CodeGenerationCustomizations,
applicationDescription: ApplicationDescription,
modelOverride: ModelOverride?) throws {
modelOverride: ModelOverride<ModelType.OverridesType>?) throws {
let targetSupport = ModelAndClientTargetSupport(modelTargetName: modelTargetName,
clientTargetName: clientTargetName)

Expand Down Expand Up @@ -160,12 +160,12 @@ struct APIGatewayClientCodeGenerator<TargetSupportType> {

extension ServiceModelCodeGenerator where TargetSupportType: ModelTargetSupport & ClientTargetSupport {

func generateFromModel<ModelType: ServiceModel>(serviceModel: ModelType,
generationType: GenerationType,
asyncAwaitAPIs: CodeGenFeatureStatus,
eventLoopFutureClientAPIs: CodeGenFeatureStatus,
minimumCompilerSupport: MinimumCompilerSupport,
clientConfigurationType: ClientConfigurationType) throws {
func generateFromModel(serviceModel: ModelType,
generationType: GenerationType,
asyncAwaitAPIs: CodeGenFeatureStatus,
eventLoopFutureClientAPIs: CodeGenFeatureStatus,
minimumCompilerSupport: MinimumCompilerSupport,
clientConfigurationType: ClientConfigurationType) throws {
switch generationType {
case .codeGenModel:
let awsModelErrorsDelegate = APIGatewayClientModelErrorsDelegate()
Expand All @@ -176,24 +176,24 @@ extension ServiceModelCodeGenerator where TargetSupportType: ModelTargetSupport
generateModelErrors(delegate: awsModelErrorsDelegate)
generateDefaultInstances(generationType: .internalTypes)
case .codeGenClient:
let clientProtocolDelegate = ClientProtocolDelegate<TargetSupportType>(
let clientProtocolDelegate = ClientProtocolDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
asyncAwaitAPIs: asyncAwaitAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
minimumCompilerSupport: minimumCompilerSupport)
let mockClientDelegate = MockAWSClientDelegate<TargetSupportType>(
let mockClientDelegate = MockAWSClientDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
isThrowingMock: false,
asyncAwaitAPIs: asyncAwaitAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
minimumCompilerSupport: minimumCompilerSupport)
let throwingClientDelegate = MockAWSClientDelegate<TargetSupportType>(
let throwingClientDelegate = MockAWSClientDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
isThrowingMock: true,
asyncAwaitAPIs: asyncAwaitAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
minimumCompilerSupport: minimumCompilerSupport)
let apiGatewayClientDelegate = APIGatewayClientDelegate<TargetSupportType>(
let apiGatewayClientDelegate = APIGatewayClientDelegate<ModelType, TargetSupportType>(
baseName: applicationDescription.baseName,
asyncAwaitAPIs: asyncAwaitAPIs,
eventLoopFutureClientAPIs: eventLoopFutureClientAPIs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public struct CoralToJSONServiceModel: Decodable {

/// Use CoralToJSONModel as a ServiceModel
extension CoralToJSONServiceModel: ServiceModel {
public static func create(data: Data, modelFormat: ModelFormat, modelOverride: ModelOverride?) throws -> CoralToJSONServiceModel {
public static func create(data: Data, modelFormat: ModelFormat, modelOverride: ModelOverride<OverridesType>?) throws -> CoralToJSONServiceModel {
let decoder = JSONDecoder()

return try decoder.decode(CoralToJSONServiceModel.self, from: data)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/CloudFormationConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private let additionalErrors: Set<String> = [
"ValidationError"]

internal struct CloudFormationConfiguration {
static let modelOverride = ModelOverride(enumerations:
static let modelOverride = ModelOverride<NoModelTypeOverrides>(enumerations:
EnumerationNaming(usingUpperCamelCase: ["ChangeSource", "ChangeAction", "ChangeType", "EvaluationType",
"HandlerErrorCode", "Replacement", "RequiresRecreation", "ResourceAttribute"]),
additionalErrors: additionalErrors)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/CloudwatchConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct CloudwatchConfiguration {
static let modelOverride = ModelOverride(fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])
static let modelOverride = ModelOverride<NoModelTypeOverrides>(fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])

static let httpClientConfiguration = HttpClientConfiguration(
retryOnUnknownError: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/CodeBuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct CodeBuildConfiguration {
static let modelOverride = ModelOverride(matchCase: [])
static let modelOverride = ModelOverride<NoModelTypeOverrides>(matchCase: [])

static let httpClientConfiguration = HttpClientConfiguration(
retryOnUnknownError: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/CodePipelineConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct CodePipelineConfiguration {
static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
enumerations: EnumerationNaming(usingUpperCamelCase: ["ActionConfigurationPropertyType",
"ActionExecutionStatus",
"ActionOwner.ThirdParty",
Expand Down
4 changes: 2 additions & 2 deletions Sources/SmokeAWSGenerate/DynamoDBConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import Foundation
import ServiceModelEntities

internal struct DynamoDBConfiguration {
static let modelOverride = ModelOverride(matchCase: ["AttributeValue"],
fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])
static let modelOverride = ModelOverride<NoModelTypeOverrides>(matchCase: ["AttributeValue"],
fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])

static let httpClientConfiguration = HttpClientConfiguration(
retryOnUnknownError: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/EC2Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private let additionalErrors: Set<String> = [
"Unavailable"]

internal struct EC2Configuration {
static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride],
additionalErrors: additionalErrors)

Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/ECRConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ServiceModelEntities

internal struct ECRConfiguration {

static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
enumerations: EnumerationNaming(usingUpperCamelCase: ["ImageFailureCode", "LayerFailureCode"]),
fieldRawTypeOverride:
[Fields.timestamp.typeDescription: CommonConfiguration.longDateOverride])
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/ECSConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct ECSConfiguration {
static let modelOverride = ModelOverride(fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])
static let modelOverride = ModelOverride<NoModelTypeOverrides>(fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])

static let httpClientConfiguration = HttpClientConfiguration(
retryOnUnknownError: true,
Expand Down
4 changes: 2 additions & 2 deletions Sources/SmokeAWSGenerate/RDSConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import Foundation
import ServiceModelEntities

internal struct RDSConfiguration {
static let modelOverride = ModelOverride(matchCase: ["AttributeValue"],
fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])
static let modelOverride = ModelOverride<NoModelTypeOverrides>(matchCase: ["AttributeValue"],
fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])

static let httpClientConfiguration = HttpClientConfiguration(
retryOnUnknownError: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/RDSDataConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct RDSDataConfiguration {
static let modelOverride = ModelOverride(fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])
static let modelOverride = ModelOverride<NoModelTypeOverrides>(fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])

static let httpClientConfiguration = HttpClientConfiguration(
retryOnUnknownError: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/S3Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal struct S3Configuration {
retriableUnknownErrors: [],
additionalClients: ["dataHttpClient": additionalHttpClient])

static let modelOverride = ModelOverride(enumerations:
static let modelOverride = ModelOverride<NoModelTypeOverrides>(enumerations:
EnumerationNaming(usingUpperCamelCase: ["Event"]),
fieldRawTypeOverride: ["Long": CommonConfiguration.intOverride])

Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/SNSConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct SNSConfiguration {
static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
codingKeyOverrides: ["AuthorizationErrorException.message": "Message",
"EndpointDisabledException.message": "Message",
"FilterPolicyLimitExceededException.message": "Message",
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/SimpleQueueConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal struct SimpleQueueConfiguration {
"TagQueue": overrideInputDescription,
"UntagQueue": overrideInputDescription]

static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
operationInputOverrides: operationInputOverrides,
codingKeyOverrides: ["ReceiveMessageResult.Messages": "Message",
"ChangeMessageVisibilityBatchRequest.Entries": "ChangeMessageVisibilityBatchRequestEntry",
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/SimpleWorkflowConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct SimpleWorkflowConfiguration {
static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
fieldRawTypeOverride:
[Fields.timestamp.typeDescription: CommonConfiguration.integerDateOverride,
"Long": CommonConfiguration.intOverride])
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/StepFunctionsConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import ServiceModelEntities

internal struct StepFunctionsConfiguration {
static let modelOverride = ModelOverride(
static let modelOverride = ModelOverride<NoModelTypeOverrides>(
enumerations: EnumerationNaming(usingUpperCamelCase:
["DecisionType", "EventType", "HistoryEventType"]),
fieldRawTypeOverride:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmokeAWSGenerate/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ struct ServiceModelDetails {
let serviceName: String
let serviceVersion: String
let baseName: String
let modelOverride: ModelOverride?
let modelOverride: ModelOverride<NoModelTypeOverrides>?
let httpClientConfiguration: HttpClientConfiguration
let signAllHeaders: Bool
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/SmokeAWSModelGenerate/APIGatewayClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ServiceModelEntities
A ModelClientDelegate that can be used to generate an
API Gateway Client from a Service Model.
*/
public struct APIGatewayClientDelegate<TargetSupportType>: ModelClientDelegate
public struct APIGatewayClientDelegate<ModelType: ServiceModel, TargetSupportType>: ModelClientDelegate
where TargetSupportType: ModelTargetSupport {
public let clientType: ClientType
public let baseName: String
Expand Down Expand Up @@ -74,7 +74,7 @@ where TargetSupportType: ModelTargetSupport {
self.defaultInvocationTraceContext = defaultInvocationTraceContext
}

public func addTypeDescription(codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
public func addTypeDescription(codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
delegate: Self,
fileBuilder: FileBuilder,
entityType: ClientEntityType) {
Expand All @@ -98,15 +98,15 @@ where TargetSupportType: ModelTargetSupport {
}
}

public func addCustomFileHeader(codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
public func addCustomFileHeader(codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
delegate: Self,
fileBuilder: FileBuilder,
fileType: ClientFileType) {
addAWSClientFileHeader(codeGenerator: codeGenerator, fileBuilder: fileBuilder, baseName: baseName, fileType: fileType,
defaultInvocationTraceContext: self.defaultInvocationTraceContext)
}

public func addCommonFunctions(codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
public func addCommonFunctions(codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
delegate: Self,
fileBuilder: FileBuilder,
sortedOperations: [(String, OperationDescription)],
Expand All @@ -129,7 +129,7 @@ where TargetSupportType: ModelTargetSupport {
entityType: entityType)
}

public func addOperationBody(codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
public func addOperationBody(codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
delegate: Self,
fileBuilder: FileBuilder, invokeType: InvokeType,
operationName: String,
Expand Down Expand Up @@ -157,7 +157,7 @@ where TargetSupportType: ModelTargetSupport {

private func addAPIGatewayClientOperationBody(
operationName: String,
codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
fileBuilder: FileBuilder,
function: APIGatewayClientFunction,
httpVerb: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal extension AWSClientDelegate {
func addAWSClientOperationBody(
name: String,
fileBuilder: FileBuilder,
codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
function: AWSClientFunction,
http: (verb: String, url: String), invokeType: InvokeType,
signAllHeaders: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal extension AWSClientDelegate {
func addAWSClientQueryOperationBody(
name: String,
fileBuilder: FileBuilder,
codeGenerator: ServiceModelCodeGenerator<TargetSupportType>,
codeGenerator: ServiceModelCodeGenerator<ModelType, TargetSupportType>,
function: AWSClientFunction,
http: (verb: String, url: String),
invokeType: InvokeType,
Expand Down
Loading

0 comments on commit c091b7e

Please sign in to comment.