openapi-changes icon indicating copy to clipboard operation
openapi-changes copied to clipboard

Incorrect changes detected when comparing left and right spec files

Open frederikprijck opened this issue 6 months ago • 0 comments
trafficstars

I am getting an unexpected output when running the CLI to detect changes made to a spec file.

I have trimmed down the original issue to a very minimal openapi specification file, but in reality this issue is resulting in over 100's of incorrectly detected changes, when all that was done was adding a new property.

When I use the following as openapi_base.json:

{
  "openapi": "3.0.3",
  "info": {
    "title": "Example",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost"
    }
  ],
  "paths": {
    "/test-url": {
      "get": {
        "summary": "Example endpoint",
        "responses": {
          "200": {
            "description": "Success!",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/bar"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "bar": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "test": {
            "type": "string",
            "description": "Some existing value.",
            "default": ""
          }
        }
      }
    }
  }
}

And the following as openapi.json

{
  "openapi": "3.0.3",
  "info": {
    "title": "Example",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost"
    }
  ],
  "paths": {
    "/test-url": {
      "get": {
        "summary": "Example endpoint",
        "responses": {
          "200": {
            "description": "Success!",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/bar"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "bar": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "test": {
            "type": "string",
            "description": "Some existing value.",
            "default": ""
          },
          "foo": {
            "type": "string",
            "description": "Foo.",
            "default": ""
          }
        }
      }
    }
  }
}

When I then run openapi-changes summary openapi_base.json openapi.json, I am getting:

└─┬Components
  └─┬bar
    ├──[+] properties (42:11)
    └─┬test
      └──[M] description (44:28)



Date: 04/28/25 | Commit: Original: openapi_base.json, Modified: openapi.json,
Document Element | Total Changes | Breaking Changes
components       | 2             | 0

 INFO  Total Changes: 2
 INFO  Modifications: 1
 INFO  Additions: 1

Which is unexpected, as the only change is the addition of the new property called Foo, I didn't change the description on the existing test property.

Interestingly, if I run the reverse comparison (openapi-changes summary openapi.json openapi_base.json), it detects the reverse change correctly:

└─┬Components
  └─┬bar
    └──[-] properties (42:11)❌



Date: 04/28/25 | Commit: Original: openapi.json, Modified: openapi_base.json,
Document Element | Total Changes | Breaking Changes
components       | 1             | 1

❌  1 Breaking changes out of 1
 INFO  Removals: 1
 INFO  Breaking Removals: 1

  ERROR   breaking changes discovered
Error: breaking changes discovered

The same issue exists with console and html-report as well.

frederikprijck avatar Apr 28 '25 21:04 frederikprijck