Defining common components

You might have noticed that our specification is not very DRY we are repeatedly specifying common responses like the 500 Internal Error. Therefore, before we learn how to specify URL parameters and our security schemes, let's first see how we can use the components root property to define common entities in a single location, and reference it throughout the OpenAPI specification. We will do this for our Create User object, as well as all our responses.

Let's start by adding the following components section as a root property to our specification:

components:  schemas:    Profile:      title: User Profile      type: object      properties:        bio:          type: string        summary:          type: string        name:          type: object          properties:            first: type: string ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.