Easily validate your REST APIs by using the swagger definitions

Swagger (now known as OpenAPI) is a well-known framework for describing the rest API specifications. Swagger removes ambiguity among multiple teams (e.g. frontend team, backend team, testing team) by having the proper rest API specification. And development and testing teams can work in parallel by referring the same spec.

Today in this post, we will look at how the swagger spec also helps us in making the automated API validation process easier using APIs. We have developed a tool named as vREST NG for validating the REST APIs and it also imports the swagger specification and makes the validation process against the imported schema much easier.

Let us see how you may validate your REST APIs by using APIs swagger specification.

Step 1: Download vREST NG

Download the vREST NG version. vREST NG provides the ability to import the swagger/OpenAPI specification to generate the test cases. If you download the Pro version for automated api testing then it will allow you to generate the data driven tests as well. Please click on the link below to download the vREST NG.

vREST NG Download Link

Step 2: Download the Swagger specification file

Write down your automated API testing specification in Swagger Editor and download the swagger specification file either in JSON or YAML format. I hope this step is pretty much clear. For this post, I will use the famous pet store swagger file.

Step 3: Import Swagger specification in vREST NG

To import swagger editor specifications in vREST NG, follow the steps below:

  1. Open vREST NG Application
  2. Create an empty directory anywhere on your system and add as a project in vREST NG.
  3. Click on that project in the rest api testing tool. It will automatically move you to the Test Cases Tab.
  4. Click on Importer button available on the top left side of the application.
  5. swagger
  6. After clicking, a popup window will appear to import the Swagger API Specifications. In the pop-up window, provide the import source as Swagger and select the desired swagger file which you want to import for the API development. In our case the file is petstore-swagger.json.
  7. api-dev
  8. Now click on Import button to import this swagger specification.

Now let us look at the data imported by vREST NG:

  1. Test Cases
  2. vREST generates the test cases automatically for each API. Tags are converted into the Test Suites automatically in the API development.


    Figure: Test Cases generated from Swagger Specification

  3. Request Parameters
  4. vREST also extracts the query or form parameters and even generates the sample request body from the schema available in the Swagger rest API specification.


    Figure: Query Parameters extracted from Swagger Specification

  5. Assertions
  6. vREST also generates the assertions for each swagger rest API spec. In the following screenshot, there are two assertions generated by vREST.

    1. The first assertion of the rest api testing tool is validating the status code of the API response.
    2. The second assertion is validating the API response schema against the schema defined in the swagger specification.
    3. assertion

      Figure: Assertions generated by vREST Swagger Importer

      And the schema is imported in the “Expected Schema” tab. You may notice that references are still maintained and are referring to global schemas available under the Configuration tab.


      Figure: Expected Schema imported from Swagger Specification

  7. Schemas
  8. Swagger definitions are imported into the Configuration tab >> Schemas Section. Which test cases can reference as we have seen in the Assertions section above. So it improves the reusability because all the schema definitions in the rest API automation can be defined globally and you may reuse them in your test cases.


    Figure: Schemas imported from Swagger Specification

Finally, We would like to have your feedback regarding the Swagger Import feature supported by vREST NG in agile development. To try out, just visit vREST NG website to download the rest API testing tool and let us know what you think about this. This API automation tool is designed to be enterprise-ready and after several years of experience and hard-learned lessons in the domain of API Testing. In future posts, I will discuss how you may incrementally update the tests for agile methodology and/or schemas whenever there is some change in swagger specification.

Have any queries?

Please send a mail to to get in touch with us.