Giter Club home page Giter Club logo

swagger-diff's Introduction

swagger-diff

Build Status jdk1.8+ Coverage Status Maven

Compare two swagger API specifications(1.x or v2.0) and render the difference to html file or markdown file.

โฌ› Command line interface (CLI)

$ java -jar swagger-diff.jar --help
Usage: java -jar swagger-diff.jar [options]
  Options:
  * -old
      old api-doc location:Json file path or Http url
  * -new
      new api-doc location:Json file path or Http url
    -v
      swagger version:1.0 or 2.0
      Default: 2.0
    -output-mode
      render mode: markdown or html
      Default: markdown
    --help

    --version
      swagger-diff tool version

Here is one command-line example(-old and -new is required, -v and -output-mode is optional):

java -jar swagger-diff.jar \
-old http://petstore.swagger.io/v2/swagger.json \
-new http://petstore.swagger.io/v2/swagger.json \
-v 2.0 \
-output-mode html > diff.html

Download the fatJar or view the changelog on the Release Page, and thanks to all contributors.

Feature

  • Supports swagger spec v1.x and v2.0.
  • Depth comparison of parameters, responses, notes, http method(GET,POST,PUT,DELETE...)
  • Supports swagger api Authorization
  • Render difference of property with Expression Language
  • html & markdown render
  • Command line interface

Maven

<dependency>
  <groupId>com.deepoove</groupId>
  <artifactId>swagger-diff</artifactId>
  <version>1.2.2</version>
</dependency>

Gradle

compile group: 'com.deepoove', name: 'swagger-diff', version: '1.2.2'

Usage

SwaggerDiff can read swagger api spec from json file or http.

SwaggerDiff diff = SwaggerDiff.compareV2("petstore_v2_1.json", "http://petstore.swagger.io/v2/swagger.json");

Swagger version

v1.x

SwaggerDiff.compareV1("petstore_v1_1.json", "petstore_v1_2.json");

v2.0

SwaggerDiff.compareV2("petstore_v2_1.json", "petstore_v2_2.json");

Render difference

HTML

String html = new HtmlRender("Changelog",
        "http://deepoove.com/swagger-diff/stylesheets/demo.css")
                .render(diff);

try {
    FileWriter fw = new FileWriter("testNewApi.html");
    fw.write(html);
    fw.close();
} catch (IOException e) {
    e.printStackTrace();
}

image

Markdown

String render = new MarkdownRender().render(diff);
try {
    FileWriter fw = new FileWriter("testDiff.md");
    fw.write(render);
    fw.close();
} catch (IOException e) {
    e.printStackTrace();
}
### What's New
---
* `GET` /pet/{petId} Find pet by ID

### What's Deprecated
---
* `POST` /pet/{petId} Updates a pet in the store with form data

### What's Changed
---
* `PUT` /pet Update an existing pet  
    Parameter

        Add body.newFeild //a feild demo by sayi
        Add body.category.newCatFeild
        Delete body.category.name
* `POST` /pet Add a new pet to the store  
    Parameter

        Add tags //add new query param demo
        Add body.newFeild //a feild demo by sayi
        Add body.category.newCatFeild
        Delete body.category.name
* `DELETE` /pet/{petId} Deletes a pet  
    Parameter

        Add newHeaderParam
* `POST` /pet/{petId}/uploadImage uploads an image for pet  
    Parameter

        petId change into not required Notes ID of pet to update change into ID of pet to update, default false
* `POST` /user Create user  
    Parameter

        Add body.newUserFeild //a new user feild demo
        Delete body.phone
* `GET` /user/login Logs user into the system  
    Parameter

        Delete password //The password for login in clear text
* `GET` /user/{username} Get user by user name  
    Return Type

        Add newUserFeild //a new user feild demo
        Delete phone
* `PUT` /user/{username} Updated user  
    Parameter

        Add body.newUserFeild //a new user feild demo
        Delete body.phone

How it works

image

swagger-diff's People

Contributors

jlamaille avatar sayi avatar sturman avatar syngu00 avatar tipsy avatar viclovsky avatar wwerner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swagger-diff's Issues

maybe a mistake

com.deepoove.swagger.diff.compare.ModelDiff#diff(io.swagger.models.Model, io.swagger.models.Model, java.lang.String, java.util.Set<io.swagger.models.Model>)

left maybe a mistake

  • Model rightSubModel = findModel(left, newDedinitions);

License type

Hello,

What's the license of this library?

Regards
Ofer

Add support for compare by JsonNode

Thank you for the great work on this library. I have a use case where I have a jsonNode containing the swagger contents (and not a URI or a file). I'd prefer not to have to write this data to a file just to use this tool.

I have a local implementation that adds a compareV2Json static method to SwaggerDiff that looks a lot like compareV2 and calls a new associated private constructor. If you have strong feelings about the method name, I'm happy to adjust.

swagger-parser already has a read(JsonNode) method.

If there's a simpler way to achieve this that doesn't require a code change, I'd appreciate a pointer.

Thanks!

Missing return type diff

In some cases return type differences are not reported

For example (see attached file) : property "liste" was deleted and property "donneeReference" was added to "rubrique" definition but no difference is being reported by the tool
CDS.zip

Array of Object Response Changes Not Detected

For example, if in petstore_v2_1.json and petstore_v2_2.json you change lines ~723 and ~722 respectively from
"schema": { "$ref": "#/definitions/User" }
to
"schema": { "type" : "array", "items" : { "$ref" : "#/definitions/User" } }
it will no longer detect that there was a change, even though it previously was caught (GET /user/{username}) when it was only a single object being returned. This is pretty important if you only return a certain object type from an endpoint as an array.

Missing Dependencies(Maven)

Looks like maven is missing the version of jcommander you are using.

Maven Central

Worked around this by excluding the jcommander dependency and depending on the latest version 1.72

Runtime incompatibility - NoSuchMethodError

The following line of code results in NoSuchMethodError:-
com.deepoove.swagger.diff.compare.ParameterDiff

    private Property mapToProperty(Parameter rightPara) {
        Property prop = new StringProperty();
        prop.setAccess(rightPara.getAccess());
        prop.setAllowEmptyValue(rightPara.getAllowEmptyValue());
        prop.setDescription(rightPara.getDescription());
        prop.setName(rightPara.getName());
        prop.setReadOnly(rightPara.isReadOnly());
        prop.setRequired(rightPara.getRequired());
        return prop;
    }

The offending call is rightPara.getAllowEmptyValue() where rightPara is of type io.swagger.models.parameters.Parameter, imported from io.swagger:swagger-models. I have trawled the versions of that module and cannot find one that is compatible (i.e. has the method getAllowEmptyValue()). Help please!!
Other than this, I'm really loving this tool! :)

OpenAPI v3 support

Hi there!

Do you have a plans to support v3 format specs?

Regards,
Serhii

Infinite recursion for comparing models

If model contains $ref like that

"definitions": {
"Pet": {
      "type": "object",
      "properties": {
        "parent_pet": {
          "$ref": "#/definitions/Pet"
        },

you get infinite recursion for models compare.

Stacktrace:

java.lang.OutOfMemoryError: Java heap space
at com.deepoove.swagger.diff.compare.ModelDiff.diff(ModelDiff.java:65)

Example:
infinite_recursion.txt

Contract testing

Are you using swagger-diff for contract testing? or just to generate the diff report?

Missing response diff

Hi, nice tool.

The tool never detects response changes. For example return code 401 disappeared in favor of 400 and the difference wasn't reported.

Provide swagger-diff as standalone tool

Hi
Could you publish this amazing library as standalone tool to make it much more easier to use? This tool should accept parameters such as OldSpecification, NewSpecification, RenderingMode, OutputFile.

SLF4J runtime error for swagger-diff v1.2.1

Hi. With new v1.2.1 I am getting this error/warning in runtime:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

This is my Java environment:

java 10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

Add support for vendor extensions

Thank you for everything you've done on this library, it's awesome. I'm currently using it in a project uses vendor extensions, and while it seems that vendor extensions aren't currently supported by swagger-diff, I currently have a local implementation that supports vendor extensions in all of the Swagger 2.0 supported locations.

It's a sizable change, due to the fact that vendor extensions can be found in so many places throughout swagger specifications, and the rendering has to be modified as well to fit this. If you think there's a better way to do this, or have strong opinions on whether/how it should be exposed, I'd love any suggestions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.