This topic explains how to create virtual assets from a Swagger definition.

Sections include:

Overview

Virtualize can automatically create a .pva based on the endpoints found in a Swagger description. Each .pva generated via the Swagger wizard will contain Message Responders for all of the defined endpoints.

This is especially helpful if the service you want to virtualize is not available for live recording, but you have access to a definition file that describes it.

Swagger Specification 1.0 - 2.0 is supported—including any Swagger core versions that are compatible with these specs (e.g., Swagger core 1.0.0, 1.2.4, 1.3.12, 1.5.0-M1, 1.5.0). Java 7 or newer is required to use Virtualize’s Swagger functionality (Java 8 or newer on Mac).

There are two main steps involved in virtualizing the application behavior from a definition file:

  1. Creating Message Responders from that definition file.
  2. Deploying those Message Responders.

Creating Message Responders from a Definition File

To automatically create Message Responders from a Swagger definition:

  1. Choose the REST> Swagger option in one of the available project/.pva/Responder suite creation wizards.
  2. In the Swagger wizard page, enter the absolute URI at which to find the Swagger definition in the Swagger Definition field. To reference a file on your local system, use a file URL (for example, file:///c:/Users/user/API/api.json).
  3. Click the Finish button.

Virtualize will then create one Message Responder configured for each resource/method/status code in the Swagger definition.  A sample message (if available) is included in the response.  If the service definition includes a  schema, that schema is used to construct and constrain the response.  

You can use the available controls to specify the response messages. For more details about reviewing and customizing the options in the tools that are created, see Message Responder Overview.

Deploying the Virtual Assets

If the .pva is created directly in the VirtualAssets project, it will be deployed automatically. Otherwise, the simplest way to deploy the virtual asset is to copy the containing .pva file into the VirtualAssets project. 

Alternatively, you could right-click the Virtualize Server view’s Local machine node, choose Add Virtual Asset, specify the .pva file that includes the virtual assets you want to deploy, then click Finish. When the wizard completes, Virtualize will automatically copy the .pva file to the VirtualAssets project.

For a more detailed discussion of deployment procedures and options, see Deploying Virtual Assets.

Customizing the Virtual Assets

For details on how to customize the Message Responder’s behavior, see Message Responder Overview.

Video Tutorial

In this video, you'll learn how to create a Parasoft Virtual Asset (PVA) from a Swagger definition.

  • No labels