Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Use Compare and Merge for SwaggerHub

DZone's Guide to

How to Use Compare and Merge for SwaggerHub

Read on to find out how to keep API documentation shipping moving forward smoothly by using Compare and Merge for SwaggerHub.

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

API description formats like Swagger act as a contract between the API provider and end consumer, clearly detailing all of the resources and operations of the API in a format that’s both human and machine readable. Using Swagger to document your RESTful APIs enables easier development, better discovery, and an overall better integration experience for the end consumer.

As a provider using Swagger to define an API, you have the responsibility to keep that contract up-to-date, which often requires managing multiple versions of your Swagger definition.

If you are someone who’s following a “code first” approach to Swagger (which means having to use annotations to generate the Swagger spec from the code of your API), you may find that there are some tweaks needed to create a well-designed definition for your API.

Whatever approach your team follows to define your API with Swagger, there’s a good chance there are a number of different people, with different skill sets and responsibilities, involved in the process.

Involving the Right People in API Documentation

Developers and API designers aren’t the only one’s involved in the design and documentation phases of the API lifecycle. If your team is serious about documenting your API, you likely have a technical writer whose responsibility is to improve your API’s usability by providing concrete documentation that works with your API’s various resources.

That person may not be actively involved in the initial development of the API, and as a result, he or she will often have to invest a lot of time understanding how to write a description for an API endpoint that is accurate and provides the right amount of context for the end user.

This documentation workflow involves a lot of collaboration between the developer, technical writer, and anyone else involved in publishing the API. And also requires the right amount of traceability to ensure that nothing breaks when making an update to the definition.

The Right Tools for Your Documentation Workflow

Here at SwaggerHub, we’ve worked hard to provide tools to make it easier for all of the members of your team to work together throughout the lifecycle of your API. With features like comments and team management, you can get feedback, raise questions, and resolve issues in real-time.

Now, we are excited to announce our newest improvement to SwaggerHub, which will make it even easier to compare Swagger definitions, review and verify changes, and accept updates to your Swagger spec.

Introducing Compare and Merge for SwaggerHub

Whether you’re updating a Swagger definition that’s already in use or adding Swagger to an existing API, it’s helpful to compare the changes you’re making before you update the API.

You can compare and merge your API specification stored in SwaggerHub with another API spec that is stored in a YAML or JSON file in your file system, be it from your local machine or to another definition stored in SwaggerHub.

Unlike a traditional diff and merge solution, the SwaggerHub Compare and Merge feature is built specifically for reviewing and implementing changes to the Swagger definition. It provides the right amount of feedback and will help validate that your API is accessible based on the changes you’re making to the definition.

Here’s a closer look at how the Compare and Merge tool works:

Compare With a Swagger Definition in SwaggerHub

  1. In SwaggerHub, open your API for editing. Switch to the needed version.
  2. Click the gear icon in the top right corner of the editor and select Compare and Merge API from the menu:
    compare-and-merge-command
  3. In the subsequent dialog, select Compare to Spec in SwaggerHub.
    compare-with-spec-in-swaggerhub
  4. In the next dialog, specify the username, API, and the API version for comparison.
    compare-with-spec-in-swaggerhub-2

To compare the API with another version of the same API, enter your username, the API name and choose another version.

  1. Click Next. SwaggerHub will validate that the API is accessible.

If the validation is successful, click Next again. This will invoke a window where you can see the difference between the APIs.

Compare With a Swagger File

  1. In SwaggerHub, open your API for editing. Switch to the needed version.
  2. Click the gear icon in the top right corner of the editor and select Compare and Merge API from the menu.
  3. In the subsequent dialog, select Compare to an external Spec.
    compare-with-spec-in-file
  4. In the next dialog, enter the URL of the desired JSON or YAML API, or specify the API file on your hard drive:
    compare-with-spec-in-file-2
  5. Click Fetch. SwaggerHub will load the specified API and check if it is valid.

If the loaded API is valid, click Compare. This will open a window where you can see the difference between the APIs (see below). If the loaded API in invalid, you will see a message describing the problem.

Below is a sample view of the Difference Window.

difference-window

Your API is on the right; the “other” API is on the left. SwaggerHub automatically detects and highlights the changed lines.

The Diff Type setting at the bottom of the window specifies the differences that SwaggerHub highlights:

Value Description
Design and Metadata SwaggerHub highlights the differences in property values and new and deleted nodes.
Design only SwaggerHub highlights only the changes in the specification structure, for example, new or deleted nodes. The differences in property values are not highlighted.

Merging Differences

  1. Click the highlighted difference line (or block) on the right or left part of the window. SwaggerHub will copy the block from the left side of the window to the right side (that is, to your API) and will remove highlighting. It will also increase the counter in the Undo button.
  2. Click Undo to revert the most recent approval, if needed. To revert several approvals, click Undo several times.
  3. After you merge all the needed differences, click Save Changes to save the changes. This will replace your API specification with the changed one.

If you wanted only to view the differences (that is, to compare two API specifications), click Cancel.

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:
swaggerhub ,api documentation ,integration

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}