DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Techniques You Should Know as a Kafka Streams Developer
  • Building Multi-Rail Payment Failover to Stop Latency Spikes and Double Debits
  • GET, POST, PUT, DELETE: Choosing HTTP Verbs in a Real .NET Core Web API, Not Just by the Textbook
  • Delegated Transport, Forked Authorization: Where Chat and AI-Agent Integrations Actually Break

Trending

  • How to Build Your Own AI SRE From Scratch
  • Frame Buffer Hashing for Visual Regression on Embedded Devices
  • AI Agents for Software Engineering and Autonomous Development Workflows
  • A Walk-Through of the DZone Article Editor

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Use Compare and Merge for SwaggerHub

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.

By 
Keshav Vasudevan
·
Dec. 07, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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.

API Merge (version control)

Published at DZone with permission of Keshav Vasudevan. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Techniques You Should Know as a Kafka Streams Developer
  • Building Multi-Rail Payment Failover to Stop Latency Spikes and Double Debits
  • GET, POST, PUT, DELETE: Choosing HTTP Verbs in a Real .NET Core Web API, Not Just by the Textbook
  • Delegated Transport, Forked Authorization: Where Chat and AI-Agent Integrations Actually Break

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook