I'm working on a python library for a REST API.I'm using python data classes to represent the structure of the returned JSON
The v2 of this API returns a slightly different object when compared to v1. Here's an example:
v1
{
"animal": {
"breed": "retreiver",
"color": "brown",
"name": "spot"
}
}
v2
{
"animal": {
"genus": "retreiver",
"color": "brown",
"name": "spot"
}
}
Biologists, please don't flame me. This is just an example
What is the right way to create a data class for this?
Create a data class with just the common attributes between v1 and v2. Then create an inheriting subclass with the different variables for v1 and v2 separately. This subclass is what is used used to represent the API response.
Maintain a separate class for each version. Even though there's some repetition, the responses aren't going to change for a version. So you don't have to modify the data class in the future anyways.
Are there any downsides with these options I haven't considered?