From e31e5b1e62150350198d1fda8727151bc3d43c96 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Thu, 3 Oct 2019 13:48:10 -0700 Subject: [PATCH 1/6] Add model override options. --- .../ServiceModelEntities/ModelOverride.swift | 14 +++++- ...deGenerator+generateDefaultInstances.swift | 2 +- ...rator+generateEnumerationDeclaration.swift | 9 +++- ...delCodeGenerator+generateModelErrors.swift | 2 +- ...ceModelCodeGenerator+shapeConversion.swift | 2 +- ...lCodeGenerator+shapeUtilityFunctions.swift | 6 +++ ...aggerServiceModel+createSwaggerModel.swift | 42 +++++++++++++++- ...aggerServiceModel+setOperationOutput.swift | 48 ++++++++++++++++++- 8 files changed, 117 insertions(+), 8 deletions(-) diff --git a/Sources/ServiceModelEntities/ModelOverride.swift b/Sources/ServiceModelEntities/ModelOverride.swift index cdf72b9..ff01b93 100644 --- a/Sources/ServiceModelEntities/ModelOverride.swift +++ b/Sources/ServiceModelEntities/ModelOverride.swift @@ -42,6 +42,12 @@ public struct ModelOverride: Codable { public let requiredOverrides: [String: Bool]? /// any additional error codes that can be returned public let additionalErrors: Set? + /// operations that should be igored. + public let ignoreOperations: Set? + /// response headers that should be igored. + public let ignoreResponseHeaders: Set? + /// overrides the default value used for an enumeration + public let defaultEnumerationValueOverride: [String: String]? public init(matchCase: Set? = nil, enumerations: EnumerationNaming? = nil, @@ -52,7 +58,10 @@ public struct ModelOverride: Codable { modelStringPatternsAreAlternativeList: Bool = false, codingKeyOverrides: [String: String]? = nil, requiredOverrides: [String: Bool]? = nil, - additionalErrors: Set? = nil) { + additionalErrors: Set? = nil, + ignoreOperations: Set? = nil, + ignoreResponseHeaders: Set? = nil, + defaultEnumerationValueOverride: [String: String]? = nil) { self.matchCase = matchCase self.enumerations = enumerations self.fieldRawTypeOverride = fieldRawTypeOverride @@ -63,6 +72,9 @@ public struct ModelOverride: Codable { self.codingKeyOverrides = codingKeyOverrides self.requiredOverrides = requiredOverrides self.additionalErrors = additionalErrors + self.ignoreOperations = ignoreOperations + self.ignoreResponseHeaders = ignoreResponseHeaders + self.defaultEnumerationValueOverride = defaultEnumerationValueOverride } public func getCodingKeyOverride(attributeName: String, inType: String?) -> String? { diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift index 16d6ba0..d23297d 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift @@ -111,7 +111,7 @@ public extension ServiceModelCodeGenerator { /** Default instance of the \(name) structure. */ - public static let __default: \(baseName)Model.\(name) = { + static let __default: \(baseName)Model.\(name) = { """) fileBuilder.incIndent() fileBuilder.incIndent() diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateEnumerationDeclaration.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateEnumerationDeclaration.swift index d382040..6d86bcd 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateEnumerationDeclaration.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateEnumerationDeclaration.swift @@ -55,7 +55,14 @@ extension ServiceModelCodeGenerator { } } - let firstInternalName = getNormalizedEnumCaseName(modelTypeName: sortedValues[0].name, + let enumCaseToUse: String + if let enumCaseToUseOverride = modelOverride?.defaultEnumerationValueOverride?[typeName] { + enumCaseToUse = enumCaseToUseOverride + } else { + enumCaseToUse = sortedValues[0].name + } + + let firstInternalName = getNormalizedEnumCaseName(modelTypeName: enumCaseToUse, inStructure: name) fileBuilder.appendEmptyLine() diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift index 858fe97..0ca6699 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift @@ -84,7 +84,7 @@ public extension ServiceModelCodeGenerator { fileBuilder.write(toFile: fileName, atFilePath: "\(applicationDescription.baseFilePath)/Sources/\(baseName)Model") } - private func getSortedErrors(allErrorTypes: Set) -> [ErrorType] { + public func getSortedErrors(allErrorTypes: Set) -> [ErrorType] { // determine if any errors will normalize to the same name var errorNameCount: [String: Int] = [:] allErrorTypes.forEach { errorIdentity in diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift index b8fd275..340f27e 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeConversion.swift @@ -34,7 +34,7 @@ internal extension ServiceModelCodeGenerator { fileBuilder.appendLine(""" public extension \(originalTypeName) { - public func as\(baseName)Model\(derivedTypeName)() -> \(derivedTypeName) { + func as\(baseName)Model\(derivedTypeName)() -> \(derivedTypeName) { return \(derivedTypeName)(\(postfix) """) diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift index 1e79194..a43583f 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift @@ -204,6 +204,12 @@ public extension ServiceModelCodeGenerator { return "`private`" } else if name == "internal" { return "`internal`" + } else if name == "as" { + return "`as`" + } else if name == "do" { + return "`do`" + } else if name == "is" { + return "`is`" } return name diff --git a/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift b/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift index 9b6d9d2..ab7d4c3 100644 --- a/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift +++ b/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift @@ -28,6 +28,41 @@ internal extension SwaggerServiceModel { var pathMembers: [String: Member] = [:] } + static func filterOperations(operations: [OperationType: SwaggerParser.Operation], + modelOverride: ModelOverride?) -> [OperationType: SwaggerParser.Operation] { + + guard let ignoreOperations = modelOverride?.ignoreOperations else { + // no filtering required + return operations + } + + var filteredOperations: [OperationType: SwaggerParser.Operation] = [:] + + operations.forEach { (key, value) in + if ignoreOperations.contains("*.*") { + return + } + + if ignoreOperations.contains("*.\(key.rawValue)") { + return + } + + if let identifier = value.identifier { + if ignoreOperations.contains("\(identifier).\(key.rawValue)") { + return + } + + if ignoreOperations.contains("\(identifier).*") { + return + } + } + + filteredOperations[key] = value + } + + return filteredOperations + } + static func createSwaggerModel(definition: Swagger, modelOverride: ModelOverride?) -> SwaggerServiceModel { var model = SwaggerServiceModel() @@ -38,15 +73,18 @@ internal extension SwaggerServiceModel { } for (path, pathDefinition) in definition.paths { + let filteredOperations = filterOperations(operations: pathDefinition.operations, + modelOverride: modelOverride) + // iterate through the operations - for (type, operation) in pathDefinition.operations { + for (type, operation) in filteredOperations { guard let identifier = operation.identifier else { continue } // if there is more than one operation for this path let operationName: String - if pathDefinition.operations.count > 1 { + if filteredOperations.count > 1 { operationName = identifier + type.rawValue.startingWithUppercase } else { operationName = identifier diff --git a/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationOutput.swift b/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationOutput.swift index bdbbc58..1ff2ac2 100644 --- a/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationOutput.swift +++ b/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationOutput.swift @@ -22,14 +22,60 @@ import SwaggerParser import Yams internal extension SwaggerServiceModel { + static func filterHeaders(operation: SwaggerParser.Operation, code: Int, headers: [String: Items], + modelOverride: ModelOverride?) -> [String: Items] { + + guard let ignoreResponseHeaders = modelOverride?.ignoreResponseHeaders else { + // no filtering required + return headers + } + + var filteredHeaders: [String: Items] = [:] + + headers.forEach { (key, value) in + if ignoreResponseHeaders.contains("*.*.*") { + return + } + + if ignoreResponseHeaders.contains("*.*.\(key)") { + return + } + + if ignoreResponseHeaders.contains("*.\(code).*") { + return + } + + if let identifier = operation.identifier { + if ignoreResponseHeaders.contains("\(identifier).\(code).\(key)") { + return + } + + if ignoreResponseHeaders.contains("\(identifier).*.\(key)") { + return + } + + if ignoreResponseHeaders.contains("\(identifier).\(code).*") { + return + } + } + + filteredHeaders[key] = value + } + + return filteredHeaders + } + static func setOperationOutput(operation: SwaggerParser.Operation, operationName: String, model: inout SwaggerServiceModel, modelOverride: ModelOverride?, description: inout OperationDescription) { // iterate through the responses for (code, response) in operation.responses { switch response { case .a(let value): + let filteredHeaders = filterHeaders(operation: operation, code: code, + headers: value.headers, modelOverride: modelOverride) + var headerMembers: [String: Member] = [:] - value.headers.enumerated().forEach { entry in + filteredHeaders.enumerated().forEach { entry in let typeName = entry.element.key.safeModelName().startingWithUppercase let headerName = "\(operationName)\(typeName)Header" From dfb600958e9b3d97f10f97112823422c1734dc54 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Wed, 9 Oct 2019 09:40:35 -0700 Subject: [PATCH 2/6] Fix Swift 5.x compile warnings. Fix linux compile issue. --- .gitignore | 1 + .../ModelClientDelegate.swift | 2 +- .../ModelErrorsDelegate.swift | 2 +- .../ServiceModelCodeGenerator.swift | 4 ++-- .../ServiceModel+getTypeMappings.swift | 2 +- .../String+nameConversions.swift | 12 ++++++------ ...Generator+createOutputStructureStubVariable.swift | 4 ++-- ...elCodeGenerator+createStructureJsonVariable.swift | 2 +- .../ServiceModelCodeGenerator+generateClient.swift | 2 +- ...ModelCodeGenerator+generateDefaultInstances.swift | 2 +- ...rviceModelCodeGenerator+generateModelErrors.swift | 4 ++-- ...Generator+generateModelOperationClientInput.swift | 2 +- ...enerator+generateModelOperationClientOutput.swift | 2 +- ...elCodeGenerator+generateModelOperationsEnum.swift | 2 +- ...eModelCodeGenerator+generateModelStructures.swift | 2 +- ...erviceModelCodeGenerator+generateModelTypes.swift | 2 +- .../ServiceModelCodeGenerator+shapeProtocol.swift | 4 ++-- ...iceModelCodeGenerator+shapeUtilityFunctions.swift | 8 ++++---- .../SwaggerServiceModel+createSwaggerModel.swift | 2 +- .../SwaggerServiceModel+setOperationInput.swift | 2 +- .../SwiftServiceModelTests.swift | 1 - 21 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 369008c..412279e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build .DS_Store .build/ +.swiftpm/ *.xcodeproj *~ diff --git a/Sources/ServiceModelCodeGeneration/ModelClientDelegate.swift b/Sources/ServiceModelCodeGeneration/ModelClientDelegate.swift index e04881b..624d90d 100644 --- a/Sources/ServiceModelCodeGeneration/ModelClientDelegate.swift +++ b/Sources/ServiceModelCodeGeneration/ModelClientDelegate.swift @@ -111,7 +111,7 @@ public enum InvokeType: String { } public extension ModelClientDelegate { - public func getHttpClientForOperation(name: String, httpClientConfiguration: HttpClientConfiguration?) -> String { + func getHttpClientForOperation(name: String, httpClientConfiguration: HttpClientConfiguration?) -> String { if let additionalClients = httpClientConfiguration?.additionalClients { for (key, value) in additionalClients { if value.operations?.contains(name) ?? false { diff --git a/Sources/ServiceModelCodeGeneration/ModelErrorsDelegate.swift b/Sources/ServiceModelCodeGeneration/ModelErrorsDelegate.swift index 725d451..b498cdb 100644 --- a/Sources/ServiceModelCodeGeneration/ModelErrorsDelegate.swift +++ b/Sources/ServiceModelCodeGeneration/ModelErrorsDelegate.swift @@ -107,7 +107,7 @@ public protocol ModelErrorsDelegate { } public extension ModelErrorsDelegate { - public var errorOptionSetConformance: String { + var errorOptionSetConformance: String { switch optionSetGeneration { case .generateWithCustomConformance(_, conformanceType: let conformanceType): return conformanceType diff --git a/Sources/ServiceModelCodeGeneration/ServiceModelCodeGenerator.swift b/Sources/ServiceModelCodeGeneration/ServiceModelCodeGenerator.swift index 44b36c8..f23ad3f 100644 --- a/Sources/ServiceModelCodeGeneration/ServiceModelCodeGenerator.swift +++ b/Sources/ServiceModelCodeGeneration/ServiceModelCodeGenerator.swift @@ -49,7 +49,7 @@ public struct ServiceModelCodeGenerator { } public extension ServiceModelCodeGenerator { - public var validationErrorType: String { + var validationErrorType: String { let baseName = applicationDescription.baseName switch customizations.validationErrorDeclaration { @@ -60,7 +60,7 @@ public extension ServiceModelCodeGenerator { } } - public var unrecognizedErrorType: String { + var unrecognizedErrorType: String { let baseName = applicationDescription.baseName switch customizations.unrecognizedErrorDeclaration { diff --git a/Sources/ServiceModelEntities/ServiceModel+getTypeMappings.swift b/Sources/ServiceModelEntities/ServiceModel+getTypeMappings.swift index 35fde65..6bd6d1c 100644 --- a/Sources/ServiceModelEntities/ServiceModel+getTypeMappings.swift +++ b/Sources/ServiceModelEntities/ServiceModel+getTypeMappings.swift @@ -50,7 +50,7 @@ public extension ServiceModel { normalizedTypeNames[internalTypeName] = updatedNormalizedNameEntry } - public static func getTypeMappings(structureDescriptions: [String: StructureDescription], + static func getTypeMappings(structureDescriptions: [String: StructureDescription], fieldDescriptions: [String: Fields]) -> [String: String] { var normalizedTypeNames: [String: NormalizedNameEntry] = [:] diff --git a/Sources/ServiceModelEntities/String+nameConversions.swift b/Sources/ServiceModelEntities/String+nameConversions.swift index 7846d17..69618fb 100644 --- a/Sources/ServiceModelEntities/String+nameConversions.swift +++ b/Sources/ServiceModelEntities/String+nameConversions.swift @@ -21,7 +21,7 @@ public extension String { /** This string starting with an uppercase. */ - public var startingWithUppercase: String { + var startingWithUppercase: String { return self.prefix(1).uppercased() + self.dropFirst() } @@ -29,7 +29,7 @@ public extension String { The normalized name for a type; either a specified type mapping from the provided service model or this string startingWithUppercase. */ - public func getNormalizedTypeName(forModel model: ServiceModel) -> String { + func getNormalizedTypeName(forModel model: ServiceModel) -> String { // if there is a mapping for this name if let mappedName = model.typeMappings[self] { return mappedName @@ -38,7 +38,7 @@ public extension String { return self.startingWithUppercase } - public func safeModelName(replacement: String = "", + func safeModelName(replacement: String = "", wildCardReplacement: String = "Star") -> String { let modifiedModelTypeName = self .replacingOccurrences(of: "-", with: replacement) @@ -56,14 +56,14 @@ public extension String { /** This string converted from upper to lower camel case. */ - public var upperToLowerCamelCase: String { + var upperToLowerCamelCase: String { return self.prefix(1).lowercased() + self.dropFirst() } /** This string converted from lower to upper camel case. */ - public var lowerToUpperCamelCase: String { + var lowerToUpperCamelCase: String { return self.prefix(1).uppercased() + self.dropFirst() } @@ -71,7 +71,7 @@ public extension String { The normalized error name; converted from upper to lower camel case and any error suffix removed. */ - public var normalizedErrorName: String { + var normalizedErrorName: String { let normalizedName = self.upperToLowerCamelCase // drop any error|fault|exception suffix diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createOutputStructureStubVariable.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createOutputStructureStubVariable.swift index 6c67e24..07656ff 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createOutputStructureStubVariable.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createOutputStructureStubVariable.swift @@ -20,7 +20,7 @@ import ServiceModelCodeGeneration import ServiceModelEntities internal extension ServiceModelCodeGenerator { - internal func createOutputStructureStubVariable( + func createOutputStructureStubVariable( type: String, fileBuilder: FileBuilder, declarationPrefix: String, @@ -90,7 +90,7 @@ internal extension ServiceModelCodeGenerator { } } - internal enum LocationOutput { + enum LocationOutput { case body case headers } diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift index 5635259..bf91431 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift @@ -37,7 +37,7 @@ private struct Value: Encodable { private func createEncoder() -> JSONEncoder { let jsonEncoder = JSONEncoder() #if os (Linux) - jsonDecoder.dateDecodingStrategy = .iso8601 + jsonEncoder.dateDecodingStrategy = .iso8601 #elseif os (OSX) if #available(OSX 10.12, *) { jsonEncoder.dateEncodingStrategy = .iso8601 diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateClient.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateClient.swift index a25671c..cb85e01 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateClient.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateClient.swift @@ -34,7 +34,7 @@ public extension ServiceModelCodeGenerator { - Parameters: - delegate: The delegate to use when generating this client. */ - public func generateClient(delegate: ModelClientDelegate) { + func generateClient(delegate: ModelClientDelegate) { let fileBuilder = FileBuilder() let baseName = applicationDescription.baseName diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift index d23297d..bc64c9d 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateDefaultInstances.swift @@ -31,7 +31,7 @@ public extension ServiceModelCodeGenerator { - Parameters: - generationType: The type of test input to generate. */ - public func generateDefaultInstances(generationType: DefaultInstancesGenerationType) { + func generateDefaultInstances(generationType: DefaultInstancesGenerationType) { let fileBuilder = FileBuilder() let baseName = applicationDescription.baseName diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift index 0ca6699..ae11726 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelErrors.swift @@ -26,7 +26,7 @@ public extension ServiceModelCodeGenerator { - Parameters: - delegate: The delegate to use when generating this client. */ - public func generateModelErrors(delegate: ModelErrorsDelegate) { + func generateModelErrors(delegate: ModelErrorsDelegate) { let fileBuilder = FileBuilder() let baseName = applicationDescription.baseName @@ -84,7 +84,7 @@ public extension ServiceModelCodeGenerator { fileBuilder.write(toFile: fileName, atFilePath: "\(applicationDescription.baseFilePath)/Sources/\(baseName)Model") } - public func getSortedErrors(allErrorTypes: Set) -> [ErrorType] { + func getSortedErrors(allErrorTypes: Set) -> [ErrorType] { // determine if any errors will normalize to the same name var errorNameCount: [String: Int] = [:] allErrorTypes.forEach { errorIdentity in diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientInput.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientInput.swift index 5694c30..f9a49a4 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientInput.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientInput.swift @@ -35,7 +35,7 @@ public extension ServiceModelCodeGenerator { /** Generate client input for each operation. */ - public func generateModelOperationClientInput() { + func generateModelOperationClientInput() { let baseName = applicationDescription.baseName let fileBuilder = FileBuilder() diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientOutput.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientOutput.swift index 2e19505..a7b278d 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientOutput.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationClientOutput.swift @@ -30,7 +30,7 @@ public extension ServiceModelCodeGenerator { /** Generate client output for each operation. */ - public func generateModelOperationClientOutput() { + func generateModelOperationClientOutput() { let baseName = applicationDescription.baseName let fileBuilder = FileBuilder() diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationsEnum.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationsEnum.swift index 65b8db3..7ee6414 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationsEnum.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelOperationsEnum.swift @@ -23,7 +23,7 @@ public extension ServiceModelCodeGenerator { /** Generate an operation enumeration for the model. */ - public func generateModelOperationsEnum() { + func generateModelOperationsEnum() { let fileBuilder = FileBuilder() let baseName = applicationDescription.baseName diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelStructures.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelStructures.swift index 5843dec..f1f18b4 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelStructures.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelStructures.swift @@ -37,7 +37,7 @@ public extension ServiceModelCodeGenerator { /** Generate the declarations for types specified in a Service Model. */ - public func generateModelStructures() { + func generateModelStructures() { let fileBuilder = FileBuilder() let baseName = applicationDescription.baseName diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelTypes.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelTypes.swift index 46b9137..aca95ed 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelTypes.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+generateModelTypes.swift @@ -23,7 +23,7 @@ public extension ServiceModelCodeGenerator { /** Generate the declarations for structures specified in a Service Model. */ - public func generateModelTypes() { + func generateModelTypes() { let fileBuilder = FileBuilder() let baseName = applicationDescription.baseName diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeProtocol.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeProtocol.swift index 407bfa3..0b2276a 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeProtocol.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeProtocol.swift @@ -20,7 +20,7 @@ import ServiceModelCodeGeneration import ServiceModelEntities internal extension ServiceModelCodeGenerator { - internal func addShapeProtocol(name: String, fileBuilder: FileBuilder, + func addShapeProtocol(name: String, fileBuilder: FileBuilder, structureElements: StructureElements) { let baseName = applicationDescription.baseName // add conformance to Equatable @@ -56,7 +56,7 @@ internal extension ServiceModelCodeGenerator { """) } - internal func addShapeDefaultFunctions(name: String, fileBuilder: FileBuilder, + func addShapeDefaultFunctions(name: String, fileBuilder: FileBuilder, structureElements: StructureElements) { let baseName = applicationDescription.baseName let willConversionFail = willShapeConversionFail(fieldName: name, alreadySeenShapes: []) diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift index a43583f..f6522a2 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+shapeUtilityFunctions.swift @@ -89,7 +89,7 @@ public extension ServiceModelCodeGenerator { - Parameters: - fieldName: the name of the field to retrieve the shape type for. */ - public func getShapeType(fieldName: String) -> + func getShapeType(fieldName: String) -> (fieldShape: String, associatedTypes: [String]) { let typeName = fieldName.getNormalizedTypeName(forModel: model) @@ -146,7 +146,7 @@ public extension ServiceModelCodeGenerator { - fieldName: the name of the field to retrieve the shape type for. - collectionAssociatedType: the associated type name for a collection type. */ - public func getShapeCategory(fieldName: String, + func getShapeCategory(fieldName: String, collectionAssociatedType: String) -> ShapeCategory { let typeName = fieldName.getNormalizedTypeName(forModel: model) @@ -221,7 +221,7 @@ public extension ServiceModelCodeGenerator { - Parameters: - modelTypeName: The model name for the type. */ - public func getNormalizedVariableName(modelTypeName: String, + func getNormalizedVariableName(modelTypeName: String, inStructure: String? = nil, reservedWordsAllowed: Bool = false) -> String { if let inStructure = inStructure, let matchCase = modelOverride?.matchCase, @@ -243,7 +243,7 @@ public extension ServiceModelCodeGenerator { - Parameters: - modelTypeName: The model name for the type. */ - public func getNormalizedEnumCaseName(modelTypeName: String, + func getNormalizedEnumCaseName(modelTypeName: String, inStructure: String, usingUpperCamelCase: Bool = false) -> String { if let usingUpperCamelCase = modelOverride?.enumerations?.usingUpperCamelCase, diff --git a/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift b/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift index ab7d4c3..ec74c0f 100644 --- a/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift +++ b/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift @@ -22,7 +22,7 @@ import SwaggerParser import Yams internal extension SwaggerServiceModel { - internal struct OperationInputMembers { + struct OperationInputMembers { var queryMembers: [String: Member] = [:] var additionalHeaderMembers: [String: Member] = [:] var pathMembers: [String: Member] = [:] diff --git a/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationInput.swift b/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationInput.swift index 3c8c9ea..12af121 100644 --- a/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationInput.swift +++ b/Sources/SwaggerServiceModel/SwaggerServiceModel+setOperationInput.swift @@ -22,7 +22,7 @@ import SwaggerParser import Yams internal extension SwaggerServiceModel { - internal struct OperationInputFields { + struct OperationInputFields { let allMembers: [String: Member] let pathFields: [String] let queryFields: [String] diff --git a/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift b/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift index 5447433..2c2edef 100644 --- a/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift +++ b/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift @@ -17,7 +17,6 @@ import XCTest @testable import ServiceModelEntities -import ServiceModelCodeGeneration class ServiceModelGenerateTests: XCTestCase { func testExample() { From f69cfdeac31ba96c43a94180b5f2ec79846b22d5 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Wed, 9 Oct 2019 09:47:53 -0700 Subject: [PATCH 3/6] Fix linux compile issue. Add Swift 5.x CI tests. --- .travis.yml | 20 +++++++++++++++++++ CITests/run | 5 ++++- README.md | 6 ++++++ ...enerator+createStructureJsonVariable.swift | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a705b3c..267bc11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,26 @@ # Matrix of required of OS and Swift releases matrix: include: + - os: linux + dist: xenial + sudo: required + services: docker + env: DOCKER_IMAGE_TAG=swift:5.1-bionic USE_SWIFT_LINT=no + - os: linux + dist: xenial + sudo: required + services: docker + env: DOCKER_IMAGE_TAG=swift:5.1-xenial USE_SWIFT_LINT=no + - os: linux + dist: xenial + sudo: required + services: docker + env: DOCKER_IMAGE_TAG=swift:5.0.1-bionic USE_SWIFT_LINT=yes + - os: linux + dist: xenial + sudo: required + services: docker + env: DOCKER_IMAGE_TAG=swift:5.0.1-xenial USE_SWIFT_LINT=yes - os: linux dist: xenial sudo: required diff --git a/CITests/run b/CITests/run index 56d14f9..7abd797 100755 --- a/CITests/run +++ b/CITests/run @@ -1,10 +1,13 @@ #!/bin/bash set -e -swiftLintVersion=0.29.0 +swiftLintVersion=0.33.0 USE_SWIFT_LINT=$1 +apt-get update +apt-get -y install libssl-dev libz-dev + workspaceRoot=($PWD) srcRoot=$workspaceRoot/sources mkdir -p $srcRoot diff --git a/README.md b/README.md index b65ddf9..5312f15 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ Swift 4.2 Compatible + +Swift 5.0 Compatible + + +Swift 5.1 Compatible + Join the Smoke Server Side community on gitter diff --git a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift index bf91431..10d1c22 100644 --- a/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift +++ b/Sources/ServiceModelGenerate/ServiceModelCodeGenerator+createStructureJsonVariable.swift @@ -37,7 +37,7 @@ private struct Value: Encodable { private func createEncoder() -> JSONEncoder { let jsonEncoder = JSONEncoder() #if os (Linux) - jsonEncoder.dateDecodingStrategy = .iso8601 + jsonEncoder.dateEncodingStrategy = .iso8601 #elseif os (OSX) if #available(OSX 10.12, *) { jsonEncoder.dateEncodingStrategy = .iso8601 From 7dc0aa308e52e928af1b6263eaf9f05aa78f146b Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Wed, 9 Oct 2019 09:53:31 -0700 Subject: [PATCH 4/6] Fix tests compile issue on linux. --- Tests/LinuxMain.swift | 4 ++-- ...erviceModelTests.swift => ServiceModelEntitiesTests.swift} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename Tests/ServiceModelEntitiesTests/{SwiftServiceModelTests.swift => ServiceModelEntitiesTests.swift} (94%) diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 83ba331..cbec0fe 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,7 +1,7 @@ import XCTest -@testable import SwiftServiceModelTests +@testable import ServiceModelEntitiesTests XCTMain([ - testCase(SwiftServiceModelTests.allTests), + testCase(ServiceModelEntitiesTests.allTests), ]) diff --git a/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift b/Tests/ServiceModelEntitiesTests/ServiceModelEntitiesTests.swift similarity index 94% rename from Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift rename to Tests/ServiceModelEntitiesTests/ServiceModelEntitiesTests.swift index 2c2edef..37e5ec9 100644 --- a/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift +++ b/Tests/ServiceModelEntitiesTests/ServiceModelEntitiesTests.swift @@ -18,7 +18,7 @@ import XCTest @testable import ServiceModelEntities -class ServiceModelGenerateTests: XCTestCase { +class ServiceModelEntitiesTests: XCTestCase { func testExample() { } From 7960f893dd9bcd350f7a2cb721343065ff3c0549 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Wed, 9 Oct 2019 10:03:05 -0700 Subject: [PATCH 5/6] Remove falling Swift 4.1 CI test. --- .travis.yml | 5 ----- README.md | 3 --- 2 files changed, 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 267bc11..61a3b81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,6 @@ matrix: sudo: required ervices: docker env: DOCKER_IMAGE_TAG=swift:4.2.1 USE_SWIFT_LINT=yes - - os: linux - dist: xenial - sudo: required - ervices: docker - env: DOCKER_IMAGE_TAG=swift:4.1.3 USE_SWIFT_LINT=no before_install: - docker pull $DOCKER_IMAGE_TAG diff --git a/README.md b/README.md index 5312f15..ca7ec43 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,6 @@ Linux -Swift 4.1 Compatible - - Swift 4.2 Compatible From 53856e0cd10d7559e53649bbc8036adb8533b13b Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Wed, 9 Oct 2019 11:09:32 -0700 Subject: [PATCH 6/6] Fix missing letter in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 61a3b81..03f82b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ matrix: - os: linux dist: xenial sudo: required - ervices: docker + services: docker env: DOCKER_IMAGE_TAG=swift:4.2.1 USE_SWIFT_LINT=yes before_install: