OpenAPITools/openapi-diff

NPE in ParametersDiff.pathUnchangedParametersChanged

stoeren opened this issue · 4 comments

In the current version there is a Nullpointer-Exception:

Unexpected exception. Reason: null
java.lang.NullPointerException
        at org.openapitools.openapidiff.core.compare.ParametersDiff.pathUnchangedParametersChanged(ParametersDiff.java:102)
        at org.openapitools.openapidiff.core.compare.ParametersDiff.diff(ParametersDiff.java:88)
        at org.openapitools.openapidiff.core.compare.OperationDiff.diff(OperationDiff.java:78)
        at org.openapitools.openapidiff.core.compare.PathDiff.diff(PathDiff.java:39)
        at org.openapitools.openapidiff.core.compare.PathsDiff.lambda$diff$3(PathsDiff.java:90)
        at java.util.LinkedHashMap$LinkedKeySet.forEach(LinkedHashMap.java:559)
        at org.openapitools.openapidiff.core.compare.PathsDiff.diff(PathsDiff.java:47)
        at org.openapitools.openapidiff.core.compare.OpenApiDiff.compare(OpenApiDiff.java:96)
        at org.openapitools.openapidiff.core.compare.OpenApiDiff.compare(OpenApiDiff.java:64)
        at org.openapitools.openapidiff.core.OpenApiCompare.fromSpecifications(OpenApiCompare.java:102)
        at org.openapitools.openapidiff.core.OpenApiCompare.fromLocations(OpenApiCompare.java:91)
        at org.openapitools.openapidiff.cli.Main.main(Main.java:175)

when passing in the attached files:
Old:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Test-API",
    "description": "Testdescription",
    "version": "v1"
  },
  "paths": {
    "/api/v1/test": {
      "get": {
        "tags": [
          "TestTag"
        ],
        "summary": "Retrieve a list Test objects",
        "description": "Usage with testId parameter is recommended.",
        "parameters": [
          {
            "name": "testId",
            "in": "query",
            "description": "rename of prop before",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dateFrom",
            "in": "query",
            "description": "Searches documents with creation date equal or younger specified timestamp",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dateTo",
            "in": "query",
            "description": "Searches documents with creation date equal or older than specified timestamp",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/TestDTO"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
	  "TestDTO": {
        "type": "object",
        "properties": {
          "Id": {
            "type": "string",
            "nullable": true
          },
          "Timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "Test": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
	},
    "securitySchemes": {
      "BearerAuth": {
        "type": "apiKey",
        "description": "Fill in your acquired bearer token here, must be like 'Bearer TOKEN_HERE'",
        "name": "Authorization",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "BearerAuth": [ ]
    }
  ]
}

new:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Test-API",
    "description": "Testdescription",
    "version": "v1"
  },
  "paths": {
    "/api/v1/test": {
      "get": {
        "tags": [
          "TestTag"
        ],
        "summary": "Retrieve a list Test objects",
        "description": "Usage with testId parameter is recommended.",
        "parameters": [
          {
            "name": "testIdWillBreak",
            "in": "query",
            "description": "rename of prop after",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dateFrom",
            "in": "query",
            "description": "Searches documents with creation date equal or younger specified timestamp",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dateTo",
            "in": "query",
            "description": "Searches documents with creation date equal or older than specified timestamp",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/TestDTO"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
	  "TestDTO": {
        "type": "object",
        "properties": {
          "Id": {
            "type": "string",
            "nullable": true
          },
          "Timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "Test": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
	},
    "securitySchemes": {
      "BearerAuth": {
        "type": "apiKey",
        "description": "Fill in your acquired bearer token here, must be like 'Bearer TOKEN_HERE'",
        "name": "Authorization",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "BearerAuth": [ ]
    }
  ]
}

expected output (Version 2.1.0-beta4):

==========================================================================
==                            API CHANGE LOG                            ==
==========================================================================
                                 Test-API
--------------------------------------------------------------------------
--                            What's Changed                            --
--------------------------------------------------------------------------
- GET    /api/v1/test
  Parameter:
    - Add testIdWillBreak in query
    - Delete testId in query
--------------------------------------------------------------------------
--                                Result                                --
--------------------------------------------------------------------------
                 API changes broke backward compatibility
--------------------------------------------------------------------------

Same here with 2.1.0-beta.6 .
Got the exception when renaming a query parameter.

Same here, any ideas?

Got the exception when renaming a query parameter.

Same here. I downgraded to 2.0.1 as a workaround.

This issue has been resolved in version 2.1.0-beta7. I added a test for this issue as it has not been covered yet with the commit. stoeren@4fb75f7