Skip to content

Examples

What you'll build

Integrate with a Pet Store API using OpenAPI Connector Generator

This example demonstrates how you can use the WSO2 Integrator: MI OpenAPI Connector Generator to easily integrate with an external PetStore REST API.

It covers generating the connector from an OpenAPI spec, importing into your integration project, and wiring it up to create and retrieve pets details.

generated connector

Prerequisites

  1. Download the sample petStore openapi contract file petstore-service.yaml file.

Set up the integration project

Step 01: Create a new integration project in WSO2 Integrator: MI for VS Code, see Create an Integration Project.

Create for integration with generated connector

Step 01: Create a new sequence or API artifact within your integration project, see Create Sequence.

generated connector

Step 02: Using petstore-service.yaml file, Generate the REST connector following the steps describe in under the section Generate OpenAPI Connector

Step 03: From the Mediator Palette, select the swagger_petstore connector that was generated from the petstore-service.yaml.

generated connector

Step 04: Create a connection by filling in the form with the required authentication details.

Property Value
Connection Name petStoreConnection
Base URL https://petstore.swagger.io/v2

Create Order

Step 05: Add the AddPet operation to your sequence or API. Provide the necessary input for the form UI for the operation. generated connector

generated connector

Step 06: Similarly, you can use the GetPetById operation to retrieve pet details by supplying the pet id. Again, make sure the response overwrites the payload.

Step 07: Add any response handling logic needed to process the output from the openAPI calls at the end of your sequence or API.

generated connector

Step 08: Deploy, Run and Test the Integration

In order to deploy and run the project, refer the build and run guide or simply use the Run button in the Visual Studio Code extension to run the integration. Once the pet details added to the petstore, you can see similar output below.

generated connector