Refactoring REST APIs

Applies to ReadyAPI 3.52, last modified on April 18, 2024

If your web service is updated, you may need to change test cases and requests in ReadyAPI. ReadyAPI offers the Refactor Definition command that simplifies this task. The command invokes a dialog box. Use it to set a correspondence between existing and new resources, methods and requests, as well as their parameters. Then, ReadyAPI will automatically update the requests and test steps in your project so that they match the updated specification.

Note: If you do not have a WADL or Swagger/OpenAPI definition for your API (for example, if you created a project from an endpoint), you will not be able to perform REST refactoring.

To use refactoring, you need the ReadyAPI Test Pro license.

1. Start refactoring

  1. Switch to Projects.

  2. Do any of the following:

    • Right-click your web service in the Navigator panel and select Refactor Definition from the context menu:

      Clicking Refactor Definition

    – or –

    • Select your web service in the Navigator panel and click Refactor on the toolbar:

      ReadyAPI toolbar

      Click the image to enlarge it.

    – or –

    • Select your web service in the Navigator panel and choose API > Refactor Definition from the main menu:

      Calling Refactor Definition from menu

The Refactor Definition dialog will appear.

2. Load the updated definition

Use the Refactor Definition dialog to select the update definition to be used during refactoring. The OpenAPI, Swagger, and WADL formats are allowed:

The Refactor Definition dialog

Click the image to enlarge it.

  1. Enter the definition URL or file name in the Definition URL edit box.

  2. Use the Definition Format settings to specify the format of the definition you are loading.

  3. Select Create New Requests to create new requests for any new methods.

  4. If the definition file specifies multiple services, select the one you need:

    Multiple services

ReadyAPI will load and analyze the new definition. In the subsequent dialog, set a correspondence between old and new operations.

3. Refactor definition

In the Refactoring REST Definitions dialog, specify which existing resources, methods and requests match new ones:

REST Refactoring

Click the image to enlarge it.

The dialog displays old items (resources, methods or requests) on the left and new items on the right. ReadyAPI automatically matches the old items with the new ones. The old items that do not match the new ones appear in red, while the new items that do not match the existing ones appear in blue.

Match existing resources, methods and requests with new ones in the following way:

  • To indicate that an existing resource, method or request matches a new one, you connect them. To do that, select an item in one panel, then select the matching item in the opposite panel and click Connect:

    REST refactoring: Connecting items

    Click the image to enlarge it.

  • If the connected resource, method or request does not match the new one, disconnect them. To do that, select an item in one of the panels (ReadyAPI will select the connected item in the opposite panel automatically) and click Disconnect:

    REST refactoring: Disconnecting items

    Click the image to enlarge it.

When you click Next, ReadyAPI will do the following:

  • If some existing resource, or its method, or a request matches the new resource, method or request (that is, if the dialog shows a thin grey line between them automatically, or if you’ve connected them manually in the dialog), then ReadyAPI will update existing items with the new item data. At that, existing child methods and requests that don’t have new matching items will not be changed. Also, ReadyAPI will add new methods and requests to the existing resource.

  • If neither existing resource, nor its methods and requests match any new resource, method or request, the existing item(s) are deleted.

  • If a new resource and its methods and requests don’t match any existing item, ReadyAPI will add these new items to the service definition stored in your project.

After you match all the needed items, click Next.

4. Refactor properties

ReadyAPI displays the Refactoring REST Definitions dialog:

ReadyAPI: Manual Refactoring

Click the image to enlarge it.

The dialog shows the differences between the current and new versions of the linked items. Review the suggested changes and adjust the final variant, if needed.

For linked methods, specify how ReadyAPI should treat representations. Select Overwrite to replace representations with the updated versions, or select Ignore to keep the current representations.

If a parameter is absent in the new definition, select what ReadyAPI should do: remove the parameter or link it with one of the new parameters. In the latter case, ReadyAPI will replace the absent parameter with the linked one. In order not to lose the current value of the parameter, make sure to select the Keep existing value option in the subsequent Parameters Refactoring dialog.

See Also

Refactoring SOAP APIs
Documenting Interfaces
Rest Services

Highlight search results