From the course: Building APIs with Swagger and the OpenAPI Specification

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Achieving reusability with components

Achieving reusability with components - REST Tutorial

From the course: Building APIs with Swagger and the OpenAPI Specification

Start my 1-month free trial

Achieving reusability with components

- [Instructor] When building API definitions, some objects such as schemas or parameters may be found within more than one operation definition. Just like programming, it's important to keep it dry, meaning do not repeat yourself. To enforce this best practice, the OpenAPI Specification provides us with a way to reuse certain objects by making them reusable components within our API definition file. Let's look at our API, we find at least three instances where we define a data structure representing a product, one within the get operation for product, one within the post operation for product, and then one within our endpoint containing the template parameter It would be very helpful if we could reuse a data structure for this product, and that's what we're going to take a look at within this lesson. To begin, we're going to navigate to the bottom of our API definition file, and then using auto-completion, we're going to look for the components object, and then within that components…

Contents