Skip to content

Commit 28fedb8

Browse files
committed
fix: Rename .Valid to .valid
1 parent 25d5cdc commit 28fedb8

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# JSONSchema Changelog
2+
3+
## Master
4+
5+
### Breaking Changes
6+
7+
- `ValidationResult.Valid` was renamed to `ValidationResult.valid`.
8+
9+
210
## 0.3.0
11+
312
### Enhancements
413

514
- Adds support for Swift 2.2.

Sources/JSONSchema.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func validators(_ root: Schema) -> (_ schema: [String:Any]) -> [Validator] {
199199
return flatten(document.map(itemsValidators))
200200
}
201201

202-
return .Valid
202+
return .valid
203203
}
204204

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

239-
return .Valid
239+
return .valid
240240
}
241241

242242
validators.append(validateItems)
@@ -292,7 +292,7 @@ func validators(_ root: Schema) -> (_ schema: [String:Any]) -> [Validator] {
292292
}
293293
}
294294

295-
return .Valid
295+
return .valid
296296
}
297297
}
298298

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

312-
return .Valid
312+
return .valid
313313
}
314314
}
315315

Sources/Validators.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import Foundation
1010

1111

1212
public enum ValidationResult {
13-
case Valid
13+
case valid
1414
case invalid([String])
1515

1616
public var valid: Bool {
1717
switch self {
18-
case .Valid:
18+
case .valid:
1919
return true
2020
case .invalid:
2121
return false
@@ -24,7 +24,7 @@ public enum ValidationResult {
2424

2525
public var errors:[String]? {
2626
switch self {
27-
case .Valid:
27+
case .valid:
2828
return nil
2929
case .invalid(let errors):
3030
return errors
@@ -50,12 +50,12 @@ func flatten(_ results:[ValidationResult]) -> ValidationResult {
5050
return .invalid(errors)
5151
}
5252

53-
return .Valid
53+
return .valid
5454
}
5555

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

6161
/// Creates a Validator which always returns an invalid result with the given error
@@ -74,36 +74,36 @@ func validateType(_ type: String) -> (_ value: Any) -> ValidationResult {
7474
case "integer":
7575
if let number = value as? NSNumber {
7676
if !CFNumberIsFloatType(number) && CFGetTypeID(number) != CFBooleanGetTypeID() {
77-
return .Valid
77+
return .valid
7878
}
7979
}
8080
case "number":
8181
if let number = value as? NSNumber {
8282
if CFGetTypeID(number) != CFBooleanGetTypeID() {
83-
return .Valid
83+
return .valid
8484
}
8585
}
8686
case "string":
8787
if value is String {
88-
return .Valid
88+
return .valid
8989
}
9090
case "object":
9191
if value is NSDictionary {
92-
return .Valid
92+
return .valid
9393
}
9494
case "array":
9595
if value is NSArray {
96-
return .Valid
96+
return .valid
9797
}
9898
case "boolean":
9999
if let number = value as? NSNumber {
100100
if CFGetTypeID(number) == CFBooleanGetTypeID() {
101-
return .Valid
101+
return .valid
102102
}
103103
}
104104
case "null":
105105
if value is NSNull {
106-
return .Valid
106+
return .valid
107107
}
108108
default:
109109
break
@@ -136,7 +136,7 @@ func anyOf(_ validators:[Validator], error:String? = nil) -> (_ value: Any) -> V
136136
for validator in validators {
137137
let result = validator(value)
138138
if result.valid {
139-
return .Valid
139+
return .valid
140140
}
141141
}
142142

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

156156
if validValidators == 1 {
157-
return .Valid
157+
return .valid
158158
}
159159

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

171-
return .Valid
171+
return .valid
172172
}
173173
}
174174

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

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

201-
return .Valid
201+
return .valid
202202
}
203203
}
204204

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

219-
return .Valid
219+
return .valid
220220
}
221221
}
222222

@@ -233,7 +233,7 @@ func validateMultipleOf(_ number: Double) -> (_ value: Any) -> ValidationResult
233233
}
234234
}
235235

236-
return .Valid
236+
return .valid
237237
}
238238
}
239239

@@ -251,7 +251,7 @@ func validateNumericLength(_ length: Double, comparitor: @escaping ((Double, Dou
251251
}
252252
}
253253

254-
return .Valid
254+
return .valid
255255
}
256256
}
257257

@@ -265,7 +265,7 @@ func validateArrayLength(_ rhs: Int, comparitor: @escaping ((Int, Int) -> Bool),
265265
}
266266
}
267267

268-
return .Valid
268+
return .valid
269269
}
270270
}
271271

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

288288
if (NSSet(array: value).count + delta) == value.count {
289-
return .Valid
289+
return .valid
290290
}
291291

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

295-
return .Valid
295+
return .valid
296296
}
297297

298298
// MARK: Object
@@ -305,21 +305,21 @@ func validatePropertiesLength(_ length: Int, comparitor: @escaping ((Int, Int) -
305305
}
306306
}
307307

308-
return .Valid
308+
return .valid
309309
}
310310
}
311311

312312
func validateRequired(_ required: [String]) -> (_ value: Any) -> ValidationResult {
313313
return { value in
314314
if let value = value as? [String:Any] {
315315
if (required.filter { r in !value.keys.contains(r) }.count == 0) {
316-
return .Valid
316+
return .valid
317317
}
318318

319319
return .invalid(["Required properties are missing '\(required)'"])
320320
}
321321

322-
return .Valid
322+
return .valid
323323
}
324324
}
325325

@@ -363,7 +363,7 @@ func validateProperties(_ properties: [String:Validator]?, patternProperties: [S
363363
return flatten(results)
364364
}
365365

366-
return .Valid
366+
return .valid
367367
}
368368
}
369369

@@ -401,25 +401,25 @@ func validateIPv4(_ value:Any) -> ValidationResult {
401401
if let ipv4 = value as? String {
402402
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)) {
403403
if expression.matches(in: ipv4, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, ipv4.characters.count)).count == 1 {
404-
return .Valid
404+
return .valid
405405
}
406406
}
407407

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

411-
return .Valid
411+
return .valid
412412
}
413413

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

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

424-
return .Valid
424+
return .valid
425425
}

Tests/JSONSchemaCases.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func makeAssertions(_ c:Case) -> ([Assertion]) {
107107
return ("\(c.description) \(test.description)", {
108108
let result = validate(test.data, schema: c.schema)
109109
switch result {
110-
case .Valid:
110+
case .valid:
111111
XCTAssertEqual(result.valid, test.value, "Result is valid")
112112
case .invalid(let errors):
113113
XCTAssertEqual(result.valid, test.value, "Failed validation: \(errors)")

0 commit comments

Comments
 (0)