From 1ea418f9ac09ebc572e0e3c85dd9d968c9579424 Mon Sep 17 00:00:00 2001 From: Jae Choi Date: Thu, 26 Sep 2019 17:05:57 -0700 Subject: [PATCH 1/2] Add map case for willShapeConversionFail --- .../ServiceModelCodeGenerator+shapeConversion.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift index dffa628..6cb4dcc 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift @@ -230,6 +230,8 @@ internal extension ServiceModelCodeGenerator { } case .list(type: let type, lengthConstraint: _): return willShapeConversionFail(fieldName: type, alreadySeenShapes: newAlreadySeenShapes) + case .map( keyType: _, let valueType, lengthConstraint: _ ): + return willShapeConversionFail( fieldName: valueType, alreadySeenShapes: newAlreadySeenShapes ) default: break } From 73493fbf01b4e72b426ed649ec7894b9554d85a8 Mon Sep 17 00:00:00 2001 From: Jae Choi Date: Thu, 26 Sep 2019 17:11:01 -0700 Subject: [PATCH 2/2] Fix 'Postix' spelling to 'Postfix' --- ...enerator+generateConversionFunctions.swift | 24 +++++++++---------- ...ceModelCodeGenerator+shapeConversion.swift | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateConversionFunctions.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateConversionFunctions.swift index a39a46c..0fa50ac 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateConversionFunctions.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateConversionFunctions.swift @@ -29,13 +29,13 @@ extension ServiceModelCodeGenerator { let willConversionFail = willShapeConversionFail(fieldName: innerType, alreadySeenShapes: []) let tryPrefix: String - let failPostix: String + let failPostfix: String if willConversionFail { tryPrefix = "try " - failPostix = " throws" + failPostfix = " throws" } else { tryPrefix = "" - failPostix = "" + failPostfix = "" } let category = getShapeCategory(fieldName: innerType, @@ -48,7 +48,7 @@ extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension Array where Element: \(type) { - func as\(baseName)Model\(typeName)()\(failPostix) -> \(baseName)Model.\(typeName) { + func as\(baseName)Model\(typeName)()\(failPostfix) -> \(baseName)Model.\(typeName) { return \(tryPrefix)self.map { \(tryPrefix)$0.as\(baseName)Model\(innerTypeName)() } } } @@ -57,7 +57,7 @@ extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension Array where \(whereClause) { - func as\(baseName)Model\(typeName)()\(failPostix) -> \(baseName)Model.\(typeName) { + func as\(baseName)Model\(typeName)()\(failPostfix) -> \(baseName)Model.\(typeName) { return \(tryPrefix)self.map { \(tryPrefix)$0.as\(baseName)Model\(innerTypeName)() } } } @@ -66,7 +66,7 @@ extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension Array where Element: CustomStringConvertible { - func as\(baseName)Model\(typeName)()\(failPostix) -> \(baseName)Model.\(typeName) { + func as\(baseName)Model\(typeName)()\(failPostfix) -> \(baseName)Model.\(typeName) { return \(tryPrefix)self.map { \(tryPrefix)$0.as\(baseName)Model\(innerTypeName)() } } } @@ -82,13 +82,13 @@ extension ServiceModelCodeGenerator { let willConversionFail = willShapeConversionFail(fieldName: valueType, alreadySeenShapes: []) let tryPrefix: String - let failPostix: String + let failPostfix: String if willConversionFail { tryPrefix = "try " - failPostix = " throws" + failPostfix = " throws" } else { tryPrefix = "" - failPostix = "" + failPostfix = "" } let category = getShapeCategory(fieldName: valueType, @@ -101,7 +101,7 @@ extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension Dictionary where Key == String, Value: \(type) { - func as\(baseName)Model\(typeName)()\(failPostix) -> \(baseName)Model.\(typeName) { + func as\(baseName)Model\(typeName)()\(failPostfix) -> \(baseName)Model.\(typeName) { return \(tryPrefix)self.mapValues { \(tryPrefix)$0.as\(baseName)Model\(valueType)() } } } @@ -110,7 +110,7 @@ extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension Dictionary where Key == String, \(whereClause) { - func as\(baseName)Model\(typeName)()\(failPostix) -> \(baseName)Model.\(typeName) { + func as\(baseName)Model\(typeName)()\(failPostfix) -> \(baseName)Model.\(typeName) { return \(tryPrefix)self.mapValues { \(tryPrefix)$0.as\(baseName)Model\(valueType)() } } } @@ -119,7 +119,7 @@ extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension Dictionary where Value: CustomStringConvertible { - func as\(baseName)Model\(typeName)()\(failPostix) -> \(baseName)Model.\(typeName) { + func as\(baseName)Model\(typeName)()\(failPostfix) -> \(baseName)Model.\(typeName) { return \(tryPrefix)self.mapValues { \(tryPrefix)$0.as\(baseName)Model\(valueType)() } } } diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift index 6cb4dcc..b8fd275 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift @@ -109,7 +109,7 @@ internal extension ServiceModelCodeGenerator { private func getListShapeToInstanceConversion(fieldName: String, type: String, variableName: String, isRequired: Bool) -> (setup: String?, fieldShape: String) { let willConversionFail = willShapeConversionFail(fieldName: type, alreadySeenShapes: []) - let failPostix = willConversionFail ? "try " : "" + let failPostfix = willConversionFail ? "try " : "" let optionalInfix = isRequired ? "" : "?" let typeName = type.getNormalizedTypeName(forModel: model) @@ -126,7 +126,7 @@ internal extension ServiceModelCodeGenerator { setupBuilder = "let converted\(capitalizedVariableName) = \(variableName)" } else { let fieldType = "[\(baseName)Model.\(typeName)]\(optionalInfix)" - setupBuilder = "let converted\(capitalizedVariableName): \(fieldType) = \(failPostix)\(variableName)\(optionalInfix).map { entry in\n" + setupBuilder = "let converted\(capitalizedVariableName): \(fieldType) = \(failPostfix)\(variableName)\(optionalInfix).map { entry in\n" if let setup = conversionDetails.setup { setup.split(separator: "\n").forEach { line in setupBuilder += " \(line)\n" } @@ -144,7 +144,7 @@ internal extension ServiceModelCodeGenerator { valueType: String, variableName: String, isRequired: Bool) -> (setup: String?, fieldShape: String) { let willConversionFail = willShapeConversionFail(fieldName: valueType, alreadySeenShapes: []) - let failPostix = willConversionFail ? "try " : "" + let failPostfix = willConversionFail ? "try " : "" let optionalInfix = isRequired ? "" : "?" let keyTypeName = keyType.getNormalizedTypeName(forModel: model) @@ -163,7 +163,7 @@ internal extension ServiceModelCodeGenerator { // if there is actually conversion on each element if conversionDetails.conversion != "entry" { - var setupBuilder = "let converted\(capitalizedVariableName): \(fieldType) = \(failPostix)\(variableName)\(optionalInfix).mapValues { entry in\n" + var setupBuilder = "let converted\(capitalizedVariableName): \(fieldType) = \(failPostfix)\(variableName)\(optionalInfix).mapValues { entry in\n" if let setup = conversionDetails.setup { setup.split(separator: "\n").forEach { line in setupBuilder += " \(line)\n" } @@ -205,9 +205,9 @@ internal extension ServiceModelCodeGenerator { let optionalInfix = isRequired ? "" : "?" let willConversionFail = willShapeConversionFail(fieldName: fieldName, alreadySeenShapes: []) - let failPostix = willConversionFail ? "try " : "" + let failPostfix = willConversionFail ? "try " : "" - fieldShape = "\(failPostix)\(variableName)\(optionalInfix).as\(baseName)Model\(fieldName)()" + fieldShape = "\(failPostfix)\(variableName)\(optionalInfix).as\(baseName)Model\(fieldName)()" } return (fieldShape, setup)