Skip to content

Commit 05258e4

Browse files
authored
Merge pull request #109 from mattpolzin/improved-extension-error
Improve error for invalid vendor extensions
2 parents 5d329e3 + 27be781 commit 05258e4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Sources/OpenAPIKit/CodableVendorExtendable.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ extension CodableVendorExtendable {
8686
return !CodingKeys.allBuiltinKeys.contains(key)
8787
}
8888

89-
guard extensions.keys.allSatisfy({ $0.lowercased().starts(with: "x-") }) else {
89+
let invalidKeys = extensions.keys.filter { !$0.lowercased().starts(with: "x-") }
90+
if !invalidKeys.isEmpty {
91+
let invalidKeysList = "[ " + invalidKeys.joined(separator: ", ") + " ]"
9092
throw InconsistencyError(
9193
subjectName: "Vendor Extension",
92-
details: "Found a vendor extension property that does not begin with the required 'x-' prefix",
94+
details: "Found at least one vendor extension property that does not begin with the required 'x-' prefix. Invalid properties: \(invalidKeysList)",
9395
codingPath: decoder.codingPath
9496
)
9597
}

Tests/OpenAPIKitErrorReportingTests/RequestContentMapErrorTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ paths:
140140

141141
let openAPIError = OpenAPI.Error(from: error)
142142

143-
XCTAssertEqual(openAPIError.localizedDescription, "Inconsistency encountered when parsing `Vendor Extension` in .content['application/json'] for the request body of the **GET** endpoint under `/hello/world`: Found a vendor extension property that does not begin with the required 'x-' prefix.")
143+
XCTAssertEqual(openAPIError.localizedDescription, "Inconsistency encountered when parsing `Vendor Extension` in .content['application/json'] for the request body of the **GET** endpoint under `/hello/world`: Found at least one vendor extension property that does not begin with the required 'x-' prefix. Invalid properties: [ invalid ].")
144144
XCTAssertEqual(openAPIError.codingPath.map { $0.stringValue }, [
145145
"paths",
146146
"/hello/world",

0 commit comments

Comments
 (0)