Skip to content

Commit

Permalink
rename Valid enum case to valid to match Swift 3 naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
angelodipaolo committed Apr 21, 2017
1 parent 447b0b2 commit 789ea50
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Sources/JSONSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func validators(_ root: Schema) -> (_ schema: [String:Any]) -> [Validator] {
return flatten(document.map(itemsValidators))
}

return .Valid
return .valid
}

validators.append(validateItems)
Expand Down Expand Up @@ -236,7 +236,7 @@ func validators(_ root: Schema) -> (_ schema: [String:Any]) -> [Validator] {
return flatten(results)
}

return .Valid
return .valid
}

validators.append(validateItems)
Expand Down Expand Up @@ -292,7 +292,7 @@ func validators(_ root: Schema) -> (_ schema: [String:Any]) -> [Validator] {
}
}

return .Valid
return .valid
}
}

Expand All @@ -304,12 +304,12 @@ func validators(_ root: Schema) -> (_ schema: [String:Any]) -> [Validator] {
if value[dependency] == nil {
return .invalid(["'\(key)' is missing it's dependency of '\(dependency)'"])
}
return .Valid
return .valid
})
}
}

return .Valid
return .valid
}
}

Expand Down
62 changes: 31 additions & 31 deletions Sources/Validators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Foundation


public enum ValidationResult {
case Valid
case valid
case invalid([String])

public var valid: Bool {
switch self {
case .Valid:
case .valid:
return true
case .invalid:
return false
Expand All @@ -24,7 +24,7 @@ public enum ValidationResult {

public var errors:[String]? {
switch self {
case .Valid:
case .valid:
return nil
case .invalid(let errors):
return errors
Expand All @@ -50,12 +50,12 @@ func flatten(_ results:[ValidationResult]) -> ValidationResult {
return .invalid(errors)
}

return .Valid
return .valid
}

/// Creates a Validator which always returns an valid result
func validValidation(_ value:Any) -> ValidationResult {
return .Valid
return .valid
}

/// Creates a Validator which always returns an invalid result with the given error
Expand All @@ -74,36 +74,36 @@ func validateType(_ type: String) -> (_ value: Any) -> ValidationResult {
case "integer":
if let number = value as? NSNumber {
if !CFNumberIsFloatType(number) && CFGetTypeID(number) != CFBooleanGetTypeID() {
return .Valid
return .valid
}
}
case "number":
if let number = value as? NSNumber {
if CFGetTypeID(number) != CFBooleanGetTypeID() {
return .Valid
return .valid
}
}
case "string":
if value is String {
return .Valid
return .valid
}
case "object":
if value is NSDictionary {
return .Valid
return .valid
}
case "array":
if value is NSArray {
return .Valid
return .valid
}
case "boolean":
if let number = value as? NSNumber {
if CFGetTypeID(number) == CFBooleanGetTypeID() {
return .Valid
return .valid
}
}
case "null":
if value is NSNull {
return .Valid
return .valid
}
default:
break
Expand Down Expand Up @@ -136,7 +136,7 @@ func anyOf(_ validators:[Validator], error:String? = nil) -> (_ value: Any) -> V
for validator in validators {
let result = validator(value)
if result.valid {
return .Valid
return .valid
}
}

Expand All @@ -154,7 +154,7 @@ func oneOf(_ validators: [Validator]) -> (_ value: Any) -> ValidationResult {
let validValidators = results.filter { $0.valid }.count

if validValidators == 1 {
return .Valid
return .valid
}

return .invalid(["\(validValidators) validates instead `oneOf`."])
Expand All @@ -168,7 +168,7 @@ func not(_ validator: @escaping Validator) -> (_ value: Any) -> ValidationResult
return .invalid(["'\(value)' does not match 'not' validation."])
}

return .Valid
return .valid
}
}

Expand All @@ -181,7 +181,7 @@ func allOf(_ validators: [Validator]) -> (_ value: Any) -> ValidationResult {
func validateEnum(_ values: [Any]) -> (_ value: Any) -> ValidationResult {
return { value in
if (values as! [NSObject]).contains(value as! NSObject) {
return .Valid
return .valid
}

return .invalid(["'\(value)' is not a valid enumeration value of '\(values)'"])
Expand All @@ -198,7 +198,7 @@ func validateLength(_ comparitor: @escaping ((Int, Int) -> (Bool)), length: Int,
}
}

return .Valid
return .valid
}
}

Expand All @@ -216,7 +216,7 @@ func validatePattern(_ pattern: String) -> (_ value: Any) -> ValidationResult {
}
}

return .Valid
return .valid
}
}

Expand All @@ -233,7 +233,7 @@ func validateMultipleOf(_ number: Double) -> (_ value: Any) -> ValidationResult
}
}

return .Valid
return .valid
}
}

Expand All @@ -251,7 +251,7 @@ func validateNumericLength(_ length: Double, comparitor: @escaping ((Double, Dou
}
}

return .Valid
return .valid
}
}

Expand All @@ -265,7 +265,7 @@ func validateArrayLength(_ rhs: Int, comparitor: @escaping ((Int, Int) -> Bool),
}
}

return .Valid
return .valid
}
}

Expand All @@ -286,13 +286,13 @@ func validateUniqueItems(_ value: Any) -> ValidationResult {
let delta = (hasTrueAndOne ? 1 : 0) + (hasFalseAndZero ? 1 : 0)

if (NSSet(array: value).count + delta) == value.count {
return .Valid
return .valid
}

return .invalid(["\(value) does not have unique items"])
}

return .Valid
return .valid
}

// MARK: Object
Expand All @@ -305,7 +305,7 @@ func validatePropertiesLength(_ length: Int, comparitor: @escaping ((Int, Int) -
}
}

return .Valid
return .valid
}
}

Expand All @@ -319,13 +319,13 @@ func validateRequired(_ required: [String]) -> (_ value: Any) -> ValidationResu
}

if missingKeys.isEmpty {
return .Valid
return .valid
}

return .invalid(["Required properties are missing '\(missingKeys)'"])
}

return .Valid
return .valid
}
}

Expand Down Expand Up @@ -369,7 +369,7 @@ func validateProperties(_ properties: [String:Validator]?, patternProperties: [S
return flatten(results)
}

return .Valid
return .valid
}
}

Expand Down Expand Up @@ -407,25 +407,25 @@ func validateIPv4(_ value:Any) -> ValidationResult {
if let ipv4 = value as? String {
if let expression = try? NSRegularExpression(pattern: "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", options: NSRegularExpression.Options(rawValue: 0)) {
if expression.matches(in: ipv4, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, ipv4.characters.count)).count == 1 {
return .Valid
return .valid
}
}

return .invalid(["'\(ipv4)' is not valid IPv4 address."])
}

return .Valid
return .valid
}

func validateIPv6(_ value:Any) -> ValidationResult {
if let ipv6 = value as? String {
var buf = UnsafeMutablePointer<Int8>.allocate(capacity: Int(INET6_ADDRSTRLEN))
if inet_pton(AF_INET6, ipv6, &buf) == 1 {
return .Valid
return .valid
}

return .invalid(["'\(ipv6)' is not valid IPv6 address."])
}

return .Valid
return .valid
}
2 changes: 1 addition & 1 deletion Tests/JSONSchemaCases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func makeAssertions(_ c:Case) -> ([Assertion]) {
return ("\(c.description) \(test.description)", {
let result = validate(test.data, schema: c.schema)
switch result {
case .Valid:
case .valid:
XCTAssertEqual(result.valid, test.value, "Result is valid")
case .invalid(let errors):
XCTAssertEqual(result.valid, test.value, "Failed validation: \(errors)")
Expand Down

0 comments on commit 789ea50

Please sign in to comment.