chapter seventeen

17 Versioning an API and handling breaking changes

 

This chapter covers

  • Updating the domain model with new concepts
  • Using subtypes and inheritance in the domain model
  • Creating composite JSON schemas from the domain model

In the last chapter, José and his team identified new requirements from the initial tests and planned a new development sprint with the goal of sharing the API with an external team for mobile app development as well as working towards making the API ready for wider release. One functional requirement to tackle as part of the sprint is the support of multiple pets per job and also pets other than dogs. The requirement implied changes to the domain model.

By going through the user stories, the PetSitter team realized that many parts of the domain model and, thus, the API description, can remain the same. The affected segment of the model is the dog concept and its relationship with the job, which we’ll now update.

In this chapter, we consider different approaches for changing the dog concept to represent different pets in the domain model and the OpenAPI definition. We look at cats and dogs for now, but the goal is finding a system that is extensible for additional species. We learn about polymorphism in domain models and the OpenAPI composition keywords and apply them. At the end, by doing that, we’ll have an updated domain model and OpenAPI description that help implementing the new functional requirements.

17.1 The problem

17.2 Polymorphism and inheritance in domain models

17.3 Updating the schemas

17.3.1 The Pet schema

17.3.2 The Dog schema

17.3.3 The Cat schema

17.4 Polymorphism and inheritance in OpenAPI

17.4.1 Composition inside the Dog/Cat schemas

17.4.2 Composition inside the Pet schema

17.5 Adding discriminators in OpenAPI

17.6 Summary