If my REST API can send partial responses back (as specified here: https://developers.google.com/gmail/api/guides/performance), is it best to make all my properties in my Swift objects optional? Or is there an another pattern to handle this?
For example, my user object:
public struct User: Decodable {
var id: Int
var firstName: String
var lastName: String
var phoneNumber: String?
var verified: Bool
}
In the DB, only phone number is optional, all the rest are required. Hence, only phone number in my swift object is marked as optional. However when it comes to the API responses, not all requests for user objects will contain all the required properties. For example, if I need to know which users are verified (GET /users?verified=true&fields=id), my response would just be a collection of user ids.
Does that mean that in Swift, I'd need to mark all properties except for id as optional?
Related question on SO: Should I use optional for properties of object models that will be parsed from JSON?