Skip to content

NPE in ParametersDiff.pathUnchangedParametersChanged #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stoeren opened this issue Mar 9, 2023 · 4 comments · Fixed by #555
Closed

NPE in ParametersDiff.pathUnchangedParametersChanged #488

stoeren opened this issue Mar 9, 2023 · 4 comments · Fixed by #555
Labels
Milestone

Comments

@stoeren
Copy link
Contributor

stoeren commented Mar 9, 2023

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
--------------------------------------------------------------------------
@joschi joschi changed the title unexpected NullPointerException NPE in ParametersDiff.pathUnchangedParametersChanged Mar 9, 2023
@stefanocke
Copy link

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

@stephan-strate
Copy link

Same here, any ideas?

@alanwguo
Copy link

Got the exception when renaming a query parameter.

Same here. I downgraded to 2.0.1 as a workaround.

@stoeren
Copy link
Contributor Author

stoeren commented Jul 31, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants