Create Virtual Services from Swagger (OpenAPI)
ldt Portal lets you create a virtual service from a Swagger (OpenAPI) 2.0 or 3.0 document.
DevTestPortal lets you create a virtual service from a Swagger (OpenAPI) 2.0 or 3.0 document.
Assume that you want to virtualize a service that is in the early stages of development. You might not be able to create the virtual service by recording. However, if you have access to a Swagger (OpenAPI) document that describes the service, you can use this approach.
The following graphic shows the
Configure Connection & Resourcesdialog, which lets you customize which operations to include.
This procedure assumes that a virtual service environment (VSE) and
DevTestPortal are running.
Responsesobject in the document has a single HTTP response code that is set to
default, the response code is mapped to the value 200.
You can create a virtual service from an OpenAPI 3.0 document using the same features that were present in Swagger 2.0. New features that were added as part of OpenAPI 3.0 are not supported.
If you are using the
$refkeyword to reference a definition, the string value must begin with a relative path, such as "
./" or "
You can test this feature with the Forward Cars demo application. Forward Cars includes a Swagger 2.0 document that describes the inventory service. The document is available at the following URL:
If Forward Cars is running on another computer, replace
localhostwith the host name or IP address of the other computer.
The Swagger document is also available in the
Datafolder of the
examplesproject. The file name is
The following video demonstrates this feature.
Follow these steps:
- SelectCreate,Virtual Servicefrom the left navigation menu.
- Provide basic information about the virtual service:
- Select theVSEserver.
- Enter a name for the virtual service.
- (Optional) Enter a description of the virtual service.
- Specify one or more Swagger documents by using any of the following approaches:
- Enter a URL that points to a Swagger document.The URL must be accessible from theVSEserver that you selected.
- ClickSelect Fileand select a Swagger document.
- ClickSelect Fileand select a zip file that contains one or more Swagger documents.
- ClickContinue.TheConfigure Connection & Resourcesdialog appears.
- You can customize which operations are included. For example, you can remove one of the operations in a set of three. You can also change the MIME type of the request and response. Depending on the contents of the Swagger document, only one MIME type might be available. When you are done with this dialog, clickFinish.
- View and edit transactions.
- (Optional) Select one or more data protocols.
- If you selected at least one data protocol, configure each one.
- Save the virtual service.
All query arguments and request header values are included in the generated virtual service regardless of the value of the require flag that is indicated in the Swagger document being parsed.
So, for example, in the following snippet of a Swagger document:
"description": "patent id to filter the results (eg. 05569676)",
The query argument
patentDocIdhas a required flag equal to
false. Regardless of that condition, the indicated query argument will be included as an argument on the generated virtual service.
All query arguments are included in the virtual service. You must edit the virtual service to remove any query arguments you do not want to include.