16 Designing schemas with composition in OpenAPI

 

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 user tests and planned a new development sprint. Part of that plan involved moving from a single Dog concept to multiple pets. This requirement implies 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 concept, which we’ll now update.

In this chapter we’ll consider different approaches for changing the Dog concept to represent different pets in the domain model and the OpenAPI definition. We’ll look at cats and dogs for now, but our goal is finding a system that will be extensible for additional species. You’ll learn about polymorphism in domain models, the OpenAPI composition keywords, and how to apply them. At the end of this chapter, we’ll have an updated domain model and OpenAPI description that will help José’s team implement the new functional requirements.

16.1 The problem

16.2 Polymorphism and inheritance in domain models

16.3 Updating the schemas

16.3.1 The Pet schema

16.3.2 The Dog schema

16.3.3 The Cat schema

16.4 Polymorphism and inheritance in OpenAPI

16.4.1 Composition inside the Dog and Cat schemas

16.4.2 Composition inside the Pet schema

16.5 Adding discriminators in OpenAPI

Summary