Skip to content

Commit 4184e4f

Browse files
committed
fix error handling under new content map structure
1 parent 8b7651f commit 4184e4f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Sources/OpenAPIKit/Encoding and Decoding Errors/ResponseDecodingError.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ extension OpenAPI.Error.Decoding.Response {
7070

7171
internal init(_ error: GenericError) {
7272
var codingPath = Self.relativePath(from: error.codingPath)
73+
74+
if error.pathIncludesSubject {
75+
codingPath = codingPath.dropLast()
76+
}
77+
7378
let code = codingPath.removeFirst().stringValue.lowercased()
7479

7580
// this part of the coding path is structurally guaranteed to be a status code

Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,11 +1173,13 @@ extension JSONSchema.IntegerContext: Decodable {
11731173
let value = try intAttempt
11741174
?? doubleAttempt.map { floatVal in
11751175
guard let integer = Int(exactly: floatVal) else {
1176+
let key = max ? CodingKeys.maximum : CodingKeys.minimum
1177+
let subject = key.rawValue
11761178
throw GenericError(
1177-
subjectName: max ? "maximum" : "minimum",
1179+
subjectName: subject,
11781180
details: "Expected an Integer literal but found a floating point value (\(String(describing: floatVal)))",
1179-
codingPath: decoder.codingPath,
1180-
pathIncludesSubject: false
1181+
codingPath: decoder.codingPath + [key],
1182+
pathIncludesSubject: true
11811183
)
11821184
}
11831185
return integer

Tests/OpenAPIKitErrorReportingTests/SchemaErrorTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ final class SchemaErrorTests: XCTestCase {
4444
"200",
4545
"content",
4646
"application/json",
47-
"schema"
47+
"schema",
48+
"maximum"
4849
])
4950
}
5051
}

0 commit comments

Comments
 (0)