From cfb5e5b2549e2be325761148db6cd042c7556007 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:49:32 +0000 Subject: [PATCH 1/3] Initial plan From 77629566d7a1c28c7750ac939b8e206ed3f26588 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:57:08 +0000 Subject: [PATCH 2/3] Fix NullPointerException in HtmlRender when schema is null Co-authored-by: DrSatyr <8143518+DrSatyr@users.noreply.github.com> --- .../openapidiff/core/output/HtmlRender.java | 16 ++++++++------ .../core/output/HtmlRenderTest.java | 22 +++++++++++++++++++ .../test/resources/null_schema_issue_1.yaml | 21 ++++++++++++++++++ .../test/resources/null_schema_issue_2.yaml | 21 ++++++++++++++++++ 4 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 core/src/test/resources/null_schema_issue_1.yaml create mode 100644 core/src/test/resources/null_schema_issue_2.yaml 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 eb4c5b88..518f1071 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 @@ -342,13 +342,15 @@ private LiTag li_missingRequest(String name, MediaType request) { } private LiTag li_changedRequest(String name, ChangedMediaType request) { - LiTag li = - li().with(div_changedSchema(request.getSchema())) - .withText(String.format("Changed body: '%s'", name)); - if (request.isIncompatible() && !showAllChanges) { - incompatibilities(li, request.getSchema()); - } else if (showAllChanges) { - allChanges(li, request.getSchema()); + LiTag li = li().withText(String.format("Changed body: '%s'", name)); + ChangedSchema schema = request.getSchema(); + if (schema != null) { + li.with(div_changedSchema(schema)); + if (request.isIncompatible() && !showAllChanges) { + incompatibilities(li, schema); + } else if (showAllChanges) { + allChanges(li, schema); + } } 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 e62268d1..2e183fa1 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 @@ -19,4 +19,26 @@ public void renderDoesNotFailWhenPropertyHasBeenRemoved() { render.render(diff, outputStreamWriter); assertThat(outputStream.toString()).isNotBlank(); } + + @Test + public void renderDoesNotFailWhenSchemaIsNullButExampleChanged() { + HtmlRender render = new HtmlRender(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations("null_schema_issue_1.yaml", "null_schema_issue_2.yaml"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()).isNotBlank(); + } + + @Test + public void renderWithShowAllChangesDoesNotFailWhenSchemaIsNullButExampleChanged() { + HtmlRender render = new HtmlRender(true); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations("null_schema_issue_1.yaml", "null_schema_issue_2.yaml"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()).isNotBlank(); + } } diff --git a/core/src/test/resources/null_schema_issue_1.yaml b/core/src/test/resources/null_schema_issue_1.yaml new file mode 100644 index 00000000..10d03cfb --- /dev/null +++ b/core/src/test/resources/null_schema_issue_1.yaml @@ -0,0 +1,21 @@ +openapi: 3.0.2 +info: + description: Test for null schema issue + title: Null Schema Test + version: 1.0.0 +paths: + /test: + post: + requestBody: + content: + application/json: + example: original example + schema: + type: string + responses: + '200': + description: Success + content: + application/json: + schema: + type: string diff --git a/core/src/test/resources/null_schema_issue_2.yaml b/core/src/test/resources/null_schema_issue_2.yaml new file mode 100644 index 00000000..9caf660c --- /dev/null +++ b/core/src/test/resources/null_schema_issue_2.yaml @@ -0,0 +1,21 @@ +openapi: 3.0.2 +info: + description: Test for null schema issue + title: Null Schema Test + version: 1.0.0 +paths: + /test: + post: + requestBody: + content: + application/json: + example: updated example + schema: + type: string + responses: + '200': + description: Success + content: + application/json: + schema: + type: string From a11280c3e9657f553d647a8da911d0ea574b0c51 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 11:25:25 +0000 Subject: [PATCH 3/3] Rename test methods and YAML files to include issue ID #865 Co-authored-by: DrSatyr <8143518+DrSatyr@users.noreply.github.com> --- .../openapidiff/core/output/HtmlRenderTest.java | 10 ++++++---- ...chema_issue_1.yaml => issue-865-null-schema-1.yaml} | 0 ...chema_issue_2.yaml => issue-865-null-schema-2.yaml} | 0 3 files changed, 6 insertions(+), 4 deletions(-) rename core/src/test/resources/{null_schema_issue_1.yaml => issue-865-null-schema-1.yaml} (100%) rename core/src/test/resources/{null_schema_issue_2.yaml => issue-865-null-schema-2.yaml} (100%) 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 2e183fa1..2d770e00 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 @@ -21,23 +21,25 @@ public void renderDoesNotFailWhenPropertyHasBeenRemoved() { } @Test - public void renderDoesNotFailWhenSchemaIsNullButExampleChanged() { + public void issue865_renderDoesNotFailWhenSchemaIsNullButExampleChanged() { HtmlRender render = new HtmlRender(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); ChangedOpenApi diff = - OpenApiCompare.fromLocations("null_schema_issue_1.yaml", "null_schema_issue_2.yaml"); + OpenApiCompare.fromLocations( + "issue-865-null-schema-1.yaml", "issue-865-null-schema-2.yaml"); render.render(diff, outputStreamWriter); assertThat(outputStream.toString()).isNotBlank(); } @Test - public void renderWithShowAllChangesDoesNotFailWhenSchemaIsNullButExampleChanged() { + public void issue865_renderWithShowAllChangesDoesNotFailWhenSchemaIsNullButExampleChanged() { HtmlRender render = new HtmlRender(true); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); ChangedOpenApi diff = - OpenApiCompare.fromLocations("null_schema_issue_1.yaml", "null_schema_issue_2.yaml"); + OpenApiCompare.fromLocations( + "issue-865-null-schema-1.yaml", "issue-865-null-schema-2.yaml"); render.render(diff, outputStreamWriter); assertThat(outputStream.toString()).isNotBlank(); } diff --git a/core/src/test/resources/null_schema_issue_1.yaml b/core/src/test/resources/issue-865-null-schema-1.yaml similarity index 100% rename from core/src/test/resources/null_schema_issue_1.yaml rename to core/src/test/resources/issue-865-null-schema-1.yaml diff --git a/core/src/test/resources/null_schema_issue_2.yaml b/core/src/test/resources/issue-865-null-schema-2.yaml similarity index 100% rename from core/src/test/resources/null_schema_issue_2.yaml rename to core/src/test/resources/issue-865-null-schema-2.yaml