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 model override option #7

Merged
merged 6 commits into from
Oct 9, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build
.DS_Store
.build/
.swiftpm/
*.xcodeproj
*~
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion CITests/run
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
</a>
<img src="https://img.shields.io/badge/os-linux-green.svg?style=flat" alt="Linux">
<a href="http://swift.org">
<img src="https://img.shields.io/badge/swift-4.1-orange.svg?style=flat" alt="Swift 4.1 Compatible">
<img src="https://img.shields.io/badge/swift-4.2-orange.svg?style=flat" alt="Swift 4.2 Compatible">
</a>
<a href="http://swift.org">
<img src="https://img.shields.io/badge/swift-4.2-orange.svg?style=flat" alt="Swift 4.2 Compatible">
<img src="https://img.shields.io/badge/swift-5.0-orange.svg?style=flat" alt="Swift 5.0 Compatible">
</a>
<a href="http://swift.org">
<img src="https://img.shields.io/badge/swift-5.1-orange.svg?style=flat" alt="Swift 5.1 Compatible">
</a>
<a href="https://gitter.im/SmokeServerSide">
<img src="https://img.shields.io/badge/chat-on%20gitter-ee115e.svg?style=flat" alt="Join the Smoke Server Side community on gitter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public struct ServiceModelCodeGenerator {
}

public extension ServiceModelCodeGenerator {
public var validationErrorType: String {
var validationErrorType: String {
let baseName = applicationDescription.baseName

switch customizations.validationErrorDeclaration {
Expand All @@ -60,7 +60,7 @@ public extension ServiceModelCodeGenerator {
}
}

public var unrecognizedErrorType: String {
var unrecognizedErrorType: String {
let baseName = applicationDescription.baseName

switch customizations.unrecognizedErrorDeclaration {
Expand Down
14 changes: 13 additions & 1 deletion Sources/ServiceModelEntities/ModelOverride.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>?
/// operations that should be igored.
public let ignoreOperations: Set<String>?
/// response headers that should be igored.
public let ignoreResponseHeaders: Set<String>?
/// overrides the default value used for an enumeration
public let defaultEnumerationValueOverride: [String: String]?

public init(matchCase: Set<String>? = nil,
enumerations: EnumerationNaming? = nil,
Expand All @@ -52,7 +58,10 @@ public struct ModelOverride: Codable {
modelStringPatternsAreAlternativeList: Bool = false,
codingKeyOverrides: [String: String]? = nil,
requiredOverrides: [String: Bool]? = nil,
additionalErrors: Set<String>? = nil) {
additionalErrors: Set<String>? = nil,
ignoreOperations: Set<String>? = nil,
ignoreResponseHeaders: Set<String>? = nil,
defaultEnumerationValueOverride: [String: String]? = nil) {
self.matchCase = matchCase
self.enumerations = enumerations
self.fieldRawTypeOverride = fieldRawTypeOverride
Expand All @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [:]

Expand Down
12 changes: 6 additions & 6 deletions Sources/ServiceModelEntities/String+nameConversions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public extension String {
/**
This string starting with an uppercase.
*/
public var startingWithUppercase: String {
var startingWithUppercase: String {
return self.prefix(1).uppercased() + self.dropFirst()
}

/**
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
Expand All @@ -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)
Expand All @@ -56,22 +56,22 @@ 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()
}

/**
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ServiceModelCodeGeneration
import ServiceModelEntities

internal extension ServiceModelCodeGenerator {
internal func createOutputStructureStubVariable(
func createOutputStructureStubVariable(
type: String,
fileBuilder: FileBuilder,
declarationPrefix: String,
Expand Down Expand Up @@ -90,7 +90,7 @@ internal extension ServiceModelCodeGenerator {
}
}

internal enum LocationOutput {
enum LocationOutput {
case body
case headers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +84,7 @@ public extension ServiceModelCodeGenerator {
fileBuilder.write(toFile: fileName, atFilePath: "\(applicationDescription.baseFilePath)/Sources/\(baseName)Model")
}

private func getSortedErrors(allErrorTypes: Set<String>) -> [ErrorType] {
func getSortedErrors(allErrorTypes: Set<String>) -> [ErrorType] {
// determine if any errors will normalize to the same name
var errorNameCount: [String: Int] = [:]
allErrorTypes.forEach { errorIdentity in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: [])
Expand Down
Loading