mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-07-10 12:18:40 -07:00
Permit missing data key for optional relationships
This prevents a decoding error when `included[].relationships.*.data` is missing, using the same logic as if it was nil.
This commit is contained in:
@@ -170,7 +170,7 @@ extension ToOneRelationship: Codable where Identifiable.Identifier: OptionalId {
|
||||
// succeeds and then attempt to coerce nil to a Identifier
|
||||
// type at which point we can store nil in `id`.
|
||||
let anyNil: Any? = nil
|
||||
if try container.decodeNil(forKey: .data) {
|
||||
if try !container.contains(.data) || container.decodeNil(forKey: .data) {
|
||||
guard let val = anyNil as? Identifiable.Identifier else {
|
||||
throw DecodingError.valueNotFound(
|
||||
Self.self,
|
||||
|
||||
Reference in New Issue
Block a user