From 538f9a4daec2f002ecc9497f2ac42b4f72b8eb5d Mon Sep 17 00:00:00 2001 From: Inf1mum Date: Sun, 15 Nov 2026 21:24:28 +0300 Subject: [PATCH 1/2] fix: render parameter notes safely in HtmlRender For a changed parameter, the Notes row in the HTML report is built from the old and new parameter descriptions. The original bug reported in #364 (both sides taken from the new parameter, so the notes always showed the new description) was already corrected, but the row still inserted the raw values: when a parameter gains a description it did not have before, j2html renders the null value as the literal text "null" in the struck-through old notes. Guard both values like the neighboring add, delete and deprecated parameter rows do, emitting an empty element when a description is absent, and add regression tests asserting that the old description is struck through and the new one shown for a changed parameter. Fixes #364. Signed-off-by: Inf1mum --- .../openapidiff/core/output/HtmlRender.java | 8 +++- .../core/output/HtmlRenderTest.java | 29 ++++++++++++++ .../resources/issue-364-param-notes-1.json | 39 ++++++++++++++++++ .../resources/issue-364-param-notes-2.json | 40 +++++++++++++++++++ 4 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 core/src/test/resources/issue-364-param-notes-1.json create mode 100644 core/src/test/resources/issue-364-param-notes-2.json diff --git a/core/src/main/java/org/openapitools/openapidiff/core/output/HtmlRender.java b/core/src/main/java/org/openapitools/openapidiff/core/output/HtmlRender.java index 441d1c9dd..6e7b55753 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/output/HtmlRender.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/output/HtmlRender.java @@ -560,9 +560,13 @@ private LiTag li_changedParam(ChangedParameter changeParam) { } if (changeDescription) { li.withText(" Notes ") - .with(del(leftParam.getDescription()).withClass(COMMENT)) + .with( + del(null == leftParam.getDescription() ? "" : leftParam.getDescription()) + .withClass(COMMENT)) .withText(" change into ") - .with(span(rightParam.getDescription()).withClass(COMMENT)); + .with( + span(null == rightParam.getDescription() ? "" : rightParam.getDescription()) + .withClass(COMMENT)); } return li; } diff --git a/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java b/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java index 2d770e00c..d8c4d0eda 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java @@ -43,4 +43,33 @@ public void issue865_renderWithShowAllChangesDoesNotFailWhenSchemaIsNullButExamp render.render(diff, outputStreamWriter); assertThat(outputStream.toString()).isNotBlank(); } + + @Test + public void issue364_renderShowsOldAndNewNotesForChangedParameter() { + HtmlRender render = new HtmlRender(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations( + "issue-364-param-notes-1.json", "issue-364-param-notes-2.json"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()) + .contains("Number of pets returned"); + assertThat(outputStream.toString()) + .contains("Maximum number of pets returned"); + } + + @Test + public void issue364_renderDoesNotShowNullWhenParameterGainsNotes() { + HtmlRender render = new HtmlRender(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations( + "issue-364-param-notes-1.json", "issue-364-param-notes-2.json"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()).doesNotContain(">null<"); + assertThat(outputStream.toString()) + .contains("Filter expression"); + } } diff --git a/core/src/test/resources/issue-364-param-notes-1.json b/core/src/test/resources/issue-364-param-notes-1.json new file mode 100644 index 000000000..c738ec237 --- /dev/null +++ b/core/src/test/resources/issue-364-param-notes-1.json @@ -0,0 +1,39 @@ +{ + "openapi": "3.0.0", + "info": { + "description": "myDesc", + "title": "myTitle", + "version": "1.0.0" + }, + "paths": { + "/pets": { + "get": { + "operationId": "listPets", + "parameters": [ + { + "name": "limit", + "in": "query", + "required": false, + "description": "Number of pets returned", + "schema": { + "type": "integer" + } + }, + { + "name": "filter", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation" + } + } + } + } + } +} diff --git a/core/src/test/resources/issue-364-param-notes-2.json b/core/src/test/resources/issue-364-param-notes-2.json new file mode 100644 index 000000000..a6affd661 --- /dev/null +++ b/core/src/test/resources/issue-364-param-notes-2.json @@ -0,0 +1,40 @@ +{ + "openapi": "3.0.0", + "info": { + "description": "myDesc", + "title": "myTitle", + "version": "1.0.0" + }, + "paths": { + "/pets": { + "get": { + "operationId": "listPets", + "parameters": [ + { + "name": "limit", + "in": "query", + "required": false, + "description": "Maximum number of pets returned", + "schema": { + "type": "integer" + } + }, + { + "name": "filter", + "in": "query", + "required": false, + "description": "Filter expression", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation" + } + } + } + } + } +} From 350e23353b3569a237682948ced5cbbb48247d7e Mon Sep 17 00:00:00 2001 From: Vadim Lazuk Date: Sat, 28 Nov 2026 18:39:39 +0300 Subject: [PATCH 2/2] Test removed parameter description rendering in HtmlRender Add a fixture pair where the limit parameter loses its description in the new spec and assert no null leaks into the rendered notes while the old description is still shown as removed text. Signed-off-by: Vadim Lazuk --- .../core/output/HtmlRenderTest.java | 14 +++++++ .../issue-364-param-notes-removed.json | 38 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 core/src/test/resources/issue-364-param-notes-removed.json diff --git a/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java b/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java index d8c4d0eda..bc458b218 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/output/HtmlRenderTest.java @@ -72,4 +72,18 @@ public void issue364_renderDoesNotShowNullWhenParameterGainsNotes() { assertThat(outputStream.toString()) .contains("Filter expression"); } + + @Test + public void issue364_renderDoesNotShowNullWhenParameterLosesNotes() { + HtmlRender render = new HtmlRender(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations( + "issue-364-param-notes-1.json", "issue-364-param-notes-removed.json"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()).doesNotContain(">null<"); + assertThat(outputStream.toString()) + .contains("Number of pets returned"); + } } diff --git a/core/src/test/resources/issue-364-param-notes-removed.json b/core/src/test/resources/issue-364-param-notes-removed.json new file mode 100644 index 000000000..918c60796 --- /dev/null +++ b/core/src/test/resources/issue-364-param-notes-removed.json @@ -0,0 +1,38 @@ +{ + "openapi": "3.0.0", + "info": { + "description": "myDesc", + "title": "myTitle", + "version": "1.0.0" + }, + "paths": { + "/pets": { + "get": { + "operationId": "listPets", + "parameters": [ + { + "name": "limit", + "in": "query", + "required": false, + "schema": { + "type": "integer" + } + }, + { + "name": "filter", + "in": "query", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation" + } + } + } + } + } +}