Easily validate your REST APIs by using the swagger definitions

Swagger (now known as OpenAPI) is a well-known framework for describing the API specifications. Swagger removes ambiguity among multiple teams (e.g. frontend team, backend team, testing team) by having the proper 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. 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 swagger specification.

Step 1: Download vREST NG

Download the vREST NG version. I will recommend you to download the Pro edition because it also provides the ability to validate APIs against the schemas provided by swagger spec. In the community edition, only the test cases will be generated from the swagger specification. 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 API 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 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. 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. 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. In our case the file is petstore-swagger.json.
  6. Now click on Import button to import this swagger specification.


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

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

    Figure: Test Cases generated from Swagger Specification
  2. Request Parameters
    vREST also extracts the query or form parameters and even generates the sample request body from the schema available in the Swagger specification.

    Figure: Query Parameters extracted from Swagger Specification
  3. Assertions
    vREST also generates the assertions for each API spec. In the following screenshot, there are two assertions generated by vREST.

    1. The first assertion 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.
      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
  4. Schemas
    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 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. To try out, just visit vREST NG website to download the tool and let us know what do you think about this. This 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 and/or schemas whenever there is some change in swagger specification.