# Generate Templates via Swagger / OpenAPI Spec

In this guide, we will look at, how you may quickly generate templates through Swagger/OpenAPI Spec.

# Importing Swagger / Open API 3 Spec into vREST NG

  • In the Test Cases Tab, just click on on the top left side of the application. (A window will pop up)
  • Select Swagger or Open API 3 for Import Source depending upon which type of specification file you have.
  • Click on
  • Find and select the Swagger Spec .json file. You may download and use this sample swagger file (opens new window).
  • And tick the option Generate Template Driven Tests.
  • Now click on button to generate the tests referencing templates.

Voila! Your Swagger Spec file is imported into vREST and test cases are created for all the requests from your Spec file, respectively.

Now let's see, what the import process has done:

  1. It has generated the templates for each API Spec with all the necessary information to fill.
  2. It has also generated a sample test case referencing the template for each template.
  3. It has generated the test suites for each tag available in the swagger file.
  4. It will add the test case in the first tag (test suite in vREST NG) available in the API spec.
  5. It will import all the definitions in the Configuration >> Schemas section.

# Generated Template Details

Now, let's take a look at a generated template for Create Contact API details:

The import process has automatically specified the template variables at various places of this template like Request Query Params, Request Body, Validation Assertions, Expected Body, and Expected Schema. Template receives data from a test case through a special variable named $data. Test Case can define this data in the Template Data section. Image: Request Form params.

Image: Template Assertions

Image: Template Expected Body

Image: Template Expected Schema

You can modify this template and hard code or remove any of the above configurations as per your needs.

Now, just define these variables' values in the template data section of your test cases. And you are ready to go. For more information, read this guide on create tests from template.