For example, let's say that I have an endpoint to get a list of buildings, that can be either apartment or house. The client can filter by apartment or house. Apartment has a property floor
that house doesn't have, so floor
will be null for all houses. For a response with a list of houses we would have
{
[
{
"address": "1, foo street",
"size": 400,
"floor": null
},
{
"address": "2, bar street",
"size": 500,
"floor": null
},
}
We can also have apartments and houses in the same response, but floor will always be null for houses.
Can I remove the floor field for houses or would that be a bad practice?
/list
and requests to a house-specific endpoint like/list/houses
:/list
responses should not change depending on the contents of the response, while/list/houses/
responses never have any reason to includefloor
."type": "apartment"
that makes it possible to tell which fields can be expected.