Add sparse fields method to ResourceObject and test it.

This commit is contained in:
Mathew Polzin
2019-08-04 23:03:56 -07:00
parent 2f3a619284
commit e0b53236bb
2 changed files with 47 additions and 3 deletions
@@ -29,3 +29,12 @@ public struct SparseField<
try resourceObject.encode(to: sparseEncoder)
}
}
public extension ResourceObject where Description.Attributes: SparsableAttributes {
/// Get a Sparse Fieldset of this `ResourceObject` that can be encoded
/// as a `PrimaryResource`.
func sparse(with fields: [Description.Attributes.CodingKeys]) -> SparseField<Description, MetaType, LinksType, EntityRawIdType> {
return SparseField(self, fields: fields)
}
}