Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

openapi-diff

> DevOps
Open source

Utility for comparing two OpenAPI specifications.

1.1K stars0 likes0 views
WebsiteGitHub

About

Utility for comparing two OpenAPI specifications.

OpenAPI-diff

Compare two OpenAPI specifications (3.x) and render the difference to HTML plain text, Markdown files, or JSON files.

Requirements

  • Java 8

Feature

  • Supports OpenAPI spec v3.0.
  • In-depth comparison of parameters, responses, endpoint, http method (GET,POST,PUT,DELETE...)
  • Supports swagger api Authorization
  • Render difference of property with Expression Language
  • HTML, Markdown, Asciidoc & JSON render

Maven

Available on Maven Central

xml

  org.openapitools.openapidiff
  openapi-diff-core
  ${openapi-diff-version}

Homebrew

Available for Mac users on brew

bash
brew install openapi-diff

Usage instructions in Usage -> Command line

Docker

Available on Docker Hub as openapitools/openapi-diff.

…

Build the image

This is only required if you want to try new changes in the Dockerfile of this project.

bash
docker build -t local-openapi-diff .

You can replace the local image name local-openapi-diff by any name of your choice.

Run an instance

In this example the $(pwd)/core/src/test/resources directory is mounted in the /specs directory of the container in readonly mode (ro).

bash
docker run --rm -t \
  -v $(pwd)/core/src/test/resources:/specs:ro \
  openapitools/openapi-diff:latest /specs/path_1.yaml /specs/path_2.yaml

The remote name openapitools/openapi-diff can be replaced with local-openapi-diff or the name you gave to your local image.

Usage

openapi-diff can read OpenAPI specs from JSON files or HTTP URLs.

Command Line

…

Maven Plugin

Add openapi-diff to your POM to show diffs when you test your Maven project. You may opt to throw an error if you have broken backwards compatibility or if your API has changed.

xml

  org.openapitools.openapidiff
  openapi-diff-maven
  ${openapi-diff-version}
  
    
      
        diff
      
      
        
        https://petstore3.swagger.io/api/v3/openapi.json
        
        ${project.basedir}/target/openapi.yaml
        
        true
        
        true
        
        ${project.basedir}/../maven/target/diff.txt
        
        ${project.basedir}/../maven/target/diff.json
        
        ${project.basedir}/../maven/target/diff.md
        
        
          my/config-file.yaml
        
        
        
          false
        
      
    
  

Direct Invocation

java
public class Main {
    public static final String OPENAPI_DOC1 = "petstore_v3_1.json";
    public static final String OPENAPI_DOC2 = "petstore_v2_2.yaml";
        
    public static void main(String[] args) {
        ChangedOpenApi diff = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2);

        //...
    }
}

Path Matching while comparing two OpenAPI paths

Path matching controls how paths from the old and new specs are paired during comparison (PathsDiff.java). The default matcher (DefaultPathMatcher) obfuscates path parameter names, meaning /users/{id} matches /users/{userId}. The default matcher fails on ambiguous signatures if the spec contains a few paths semantically identical. In case this behaviour is not fitting your use case, you can implement your own matching strategy.

You can plug in a custom matcher via OpenApiDiffOptions implementing the PathMatcher interface:

java
OpenApiDiffOptions options = OpenApiDiffOptions
    .builder()
    .pathMatcher(new MyCustomPathMatcher())
    .build();

ChangedOpenApi diff = OpenApiCompare.fromLocations(oldSpec, newSpec, null, options);

Render difference


HTML

java
HtmlRender htmlRender = new HtmlRender("Changelog", "http://deepoove.com/swagger-diff/stylesheets/demo.css");
FileOutputStream outputStream = new FileOutputStream("testDiff.html");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
htmlRender.render(diff, outputStreamWriter);

Markdown

java
MarkdownRender markdownRender = new MarkdownRender();
FileOutputStream outputStream = new FileOutputStream("testDiff.md");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
markdownRender.render(diff, outputStreamWriter);

Asciidoc

java
AsciidocRender asciidocRender = new AsciidocRender();
FileOutputStream outputStream = new FileOutputStream("testDiff.adoc");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
asciidocRender.render(diff, outputStreamWriter);

JSON

java
JsonRender jsonRender = new JsonRender();
FileOutputStream outputStream = new FileOutputStream("testDiff.json");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
jsonRender.render(diff, outputStreamWriter);

Extensions

This project uses Java Service Provider Interface (SPI) so additional extensions can be added.

To build your own extension, you simply need to create a src/main/resources/META-INF/services/org.openapitools.openapidiff.core.compare.ExtensionDiff file with the full classname of your implementation. Your class must also implement the org.openapitools.openapidiff.core.compare.ExtensionDiff interface. Then, including your library with the openapi-diff module will cause it to be triggered automatically.

Examples

CLI Output

…

Markdown

…

JSON

…

License

openapi-diff is released under the Apache License 2.0.

Thanks

  • Adarsh Sharma / adarshsharma
  • Quentin Desramé / quen2404
  • Sayi for his project swagger-diff which was a source of inspiration for this tool

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaapidiffopenapiopenapi-diff

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理