Skip to content

Commit 3fac475

Browse files
authored
Merge pull request #309 from mattpolzin/fix-double-validation
fix double-validation error reporting
2 parents 0f712cc + 922f215 commit 3fac475

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Sources/OpenAPIKit/Validator/Validator.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ extension OpenAPI.Document {
2626
let validator = _Validator(document: self, validations: validator.validations)
2727
var container = validator.singleValueContainer()
2828

29-
// we kick things off by applying validations to the root (OpenAPI.Document)
30-
// and then encoding with the single value container.
31-
// After this, validations are only applied by keyed/unkeyed containers and
32-
// by the leaf node methods of the single value container.
33-
validator.applyValidations(to: self)
29+
// Validation is done by "encoding"
3430
try container.encode(self)
3531

3632
if !validator.errors.isEmpty {

Tests/OpenAPIKitTests/Validator/BuiltinValidationTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class BuiltinValidationTests: XCTestCase {
2424
let error = error as? ValidationErrorCollection
2525
XCTAssertEqual(error?.values.first?.reason, "Failed to satisfy: Document contains at least one path")
2626
XCTAssertEqual(error?.values.first?.codingPath.map { $0.stringValue }, ["paths"])
27+
XCTAssertEqual(error?.values.count, 1)
2728
}
2829
}
2930

@@ -57,6 +58,7 @@ final class BuiltinValidationTests: XCTestCase {
5758
let error = error as? ValidationErrorCollection
5859
XCTAssertEqual(error?.values.first?.reason, "Failed to satisfy: Paths contain at least one operation")
5960
XCTAssertEqual(error?.values.first?.codingPath.map { $0.stringValue }, ["paths", "/hello/world"])
61+
XCTAssertEqual(error?.values.count, 1)
6062
}
6163
}
6264

0 commit comments

Comments
 (0)