This topic explains how to create virtual assets from an OpenAPI/Swagger definition.

Sections include:

Overview

Virtualize can automatically create a .pva based on the endpoints found in an OpenAPI/Swagger description. Each .pva 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.

The following specifications are supported:

  • Swagger 1.0 - 2.0. This includes 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).
  • OpenAPI/Swagger 3.0.

Java 7 or newer is required to use this 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 OpenAPI/Swagger definition:

  1. Right-click on a virtual asset and choose Add New> Virtual Asset (.pva) File . . . 
  2. Specify a name for the file and click Next.
  3. Choose the REST> OpenAPI/Swagger option and click Next.
  4. In the OpenAPI/Swagger wizard page, enter the absolute URI for the definition file or click Browse to locate the file on your local system.
  5. Click Finish button.

Virtualize will then create one Message Responder configured for each resource/method/status code in the OpenAPI/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.

  • No labels