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/.travis.yml b/.travis.yml
index a705b3c..03f82b4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,13 +4,28 @@ matrix:
- os: linux
dist: xenial
sudo: required
- ervices: docker
- env: DOCKER_IMAGE_TAG=swift:4.2.1 USE_SWIFT_LINT=yes
+ 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
- ervices: docker
- env: DOCKER_IMAGE_TAG=swift:4.1.3 USE_SWIFT_LINT=no
+ 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
+ services: docker
+ env: DOCKER_IMAGE_TAG=swift:4.2.1 USE_SWIFT_LINT=yes
before_install:
- docker pull $DOCKER_IMAGE_TAG
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..ca7ec43 100644
--- a/README.md
+++ b/README.md
@@ -4,10 +4,13 @@
-
+
-
+
+
+
+
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/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/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..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)
- jsonDecoder.dateDecodingStrategy = .iso8601
+ jsonEncoder.dateEncodingStrategy = .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 16d6ba0..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
@@ -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..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")
}
- private 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+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+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 1e79194..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)
@@ -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
@@ -215,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,
@@ -237,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 9b6d9d2..ec74c0f 100644
--- a/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift
+++ b/Sources/SwaggerServiceModel/SwaggerServiceModel+createSwaggerModel.swift
@@ -22,12 +22,47 @@ import SwaggerParser
import Yams
internal extension SwaggerServiceModel {
- internal struct OperationInputMembers {
+ struct OperationInputMembers {
var queryMembers: [String: Member] = [:]
var additionalHeaderMembers: [String: Member] = [:]
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+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/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"
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 91%
rename from Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift
rename to Tests/ServiceModelEntitiesTests/ServiceModelEntitiesTests.swift
index 5447433..37e5ec9 100644
--- a/Tests/ServiceModelEntitiesTests/SwiftServiceModelTests.swift
+++ b/Tests/ServiceModelEntitiesTests/ServiceModelEntitiesTests.swift
@@ -17,9 +17,8 @@
import XCTest
@testable import ServiceModelEntities
-import ServiceModelCodeGeneration
-class ServiceModelGenerateTests: XCTestCase {
+class ServiceModelEntitiesTests: XCTestCase {
func testExample() {
}