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.

Reusing parameters

Reusing parameters - REST Tutorial

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

Start my 1-month free trial

Reusing parameters

- [Instructor] Query parameters are another object that can be reused in API definition files. If we take a look at our API definition, we'll see, within our product endpoint, that we have the paging parameters that we established for the get operation. These parameters could easily be reused for other endpoints that require paging. So let's go ahead and copy these, because we're going to move them within the component section to make them reusable. To do that, we simply add the parameters object to the component section, and then we need to provide a name for each of the parameters that we want to define. So, in this case, I'm going to supply a parameter named pageNumber, and then we're going to grab the YAML that defines these parameters and paste it in, and then we simply adjust the indentation to conform to YAML standards. And then we'll need to build out our second parameter, which is going to be the pageSize, and here we'll, once again, need to do some indentation. And once…

Contents