chapter seven

7 Describing data with JSON Schema in OpenAPI

 

This chapter covers

  • When and how to leverage data description capabilities of OpenAPI during API design
  • Describing data with JSON Schema in the context of OpenAPI
  • Describing reusable resource data models with JSON Schema in an OpenAPI document
  • Describing operations input and output data with JSON Schema in an OpenAPI document

Once we have described the HTTP operations with OpenAPI, we can move on to the next step and leverage JSON Schema to describe the fine-grained data. As discussed in chapter 6, using such standards simplifies the API design process, reduces errors, and benefits the whole API lifecycle.

This chapter introduces the JSON Schema format and overviews how to describe data while designing it. It then briefly discusses JSON Schema authoring in the context of OpenAPI authoring. The rest of the chapter describes the "Online Shopping" data modeled in chapter 5 with JSON Schema and OpenAPI, demonstrating how to describe resource models and use them to describe operations input and output data based on their locations.

7.1 Overviewing data description

7.1.1 Introducing JSON Schema

7.1.2 Contrasting an OpenAPI document leveraging JSON Schema with our API spreadsheet

7.1.3 Describing data while designing it

7.2 Authoring JSON Schema data model in OpenAPI

7.3 Adding complete resource data models to the OpenAPI document

7.3.1 Choosing a location for the resource model in the OpenAPI document

7.3.2 Initiating the resource model description

7.4 Describing complete resource data models with JSON Schema

7.4.1 Describing an object

7.4.2 Adding properties to an object

7.4.3 Describing an atomic property

7.4.4 Describing an object property

7.4.5 Describing an array property

7.4.6 Stating which properties are required

7.5 Describing operations input and output data

7.6 Describing operations non-body data

7.6.1 Describing non-body request parameters with inline schemas

7.6.2 Describing response headers with inline schemas

7.7 Describing operations body data