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..c1b262535 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 @@ -203,6 +203,10 @@ private OlTag ol_changed(List changedOperations) { .orElse(""); UlTag ul_detail = ul().withClass("detail"); + if (result(changedOperation.getDescription()).isDifferent()) { + ul_detail.with( + li().with(h3("Description")).with(ul_description(changedOperation.getDescription()))); + } if (result(changedOperation.getOperationId()).isDifferent()) { ul_detail.with( li().with(h3("Operation ID")).with(ul_operation_id(changedOperation.getOperationId()))); @@ -576,4 +580,17 @@ private UlTag ul_operation_id(ChangedOperationId changedOperationId) { + " to " + Optional.ofNullable(changedOperationId.getRight()).orElse(""))); } + + private UlTag ul_description(ChangedMetadata changedMetadata) { + return ul().withClass("change description") + .with( + li().withText("Changed description: ") + .with( + del(null == changedMetadata.getLeft() ? "" : changedMetadata.getLeft()) + .withClass(COMMENT)) + .withText(" change into ") + .with( + span(null == changedMetadata.getRight() ? "" : changedMetadata.getRight()) + .withClass(COMMENT))); + } } diff --git a/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java b/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java index 531fd3809..30c9b387d 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java @@ -133,6 +133,10 @@ protected void listEndpoints( operation.getHttpMethod().toString(), operation.getPathUrl(), operation.getSummary())); + if (result(operation.getDescription()).isDifferent()) { + safelyAppend(outputStreamWriter, titleH5("Description:")); + safelyAppend(outputStreamWriter, metadata("description", operation.getDescription())); + } if (result(operation.getOperationId()).isDifferent()) { safelyAppend(outputStreamWriter, titleH5("Operation ID:")); safelyAppend(outputStreamWriter, operationId(operation.getOperationId())); 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..cde79e5d6 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,34 @@ public void issue865_renderWithShowAllChangesDoesNotFailWhenSchemaIsNullButExamp render.render(diff, outputStreamWriter); assertThat(outputStream.toString()).isNotBlank(); } + + @Test + public void issue857_renderShowsChangedOperationDescription() { + HtmlRender render = new HtmlRender(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations( + "issue-857-operation-description-1.json", "issue-857-operation-description-2.json"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()).contains("Changed description:"); + assertThat(outputStream.toString()).contains("Sample description"); + assertThat(outputStream.toString()) + .contains("Sample description changed"); + } + + @Test + public void issue857_renderWithShowAllChangesShowsChangedOperationDescription() { + HtmlRender render = new HtmlRender(true); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations( + "issue-857-operation-description-1.json", "issue-857-operation-description-2.json"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()).contains("Changed description:"); + assertThat(outputStream.toString()).contains("Sample description"); + assertThat(outputStream.toString()) + .contains("Sample description changed"); + } } diff --git a/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java b/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java index 597882105..367ad698b 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java @@ -20,6 +20,21 @@ public void renderDoesNotFailWhenPropertyHasBeenRemoved() { assertThat(outputStream.toString()).isNotBlank(); } + @Test + public void issue857_renderShowsChangedOperationDescription() { + MarkdownRender render = new MarkdownRender(); + render.setShowChangedMetadata(true); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); + ChangedOpenApi diff = + OpenApiCompare.fromLocations( + "issue-857-operation-description-1.json", "issue-857-operation-description-2.json"); + render.render(diff, outputStreamWriter); + assertThat(outputStream.toString()) + .contains( + "Changed description:\n> Sample description\n\n\nto:\n> Sample description changed"); + } + @Test public void renderDoesNotCauseStackOverflowWithRecursiveDefinitions() { MarkdownRender render = new MarkdownRender(); diff --git a/core/src/test/resources/issue-857-operation-description-1.json b/core/src/test/resources/issue-857-operation-description-1.json new file mode 100644 index 000000000..0ccef0d11 --- /dev/null +++ b/core/src/test/resources/issue-857-operation-description-1.json @@ -0,0 +1,108 @@ +{ + "components": { + "schemas": { + }, + "securitySchemes": { + } + }, + "info": { + "description": "This is the swagger documentation for sample-api. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). ", + "title": "sample-api", + "version": "3.47.0" + }, + "openapi": "3.1.0", + "paths": { + "/sample-api/export": { + "get": { + "description": "Export into MS Excel", + "operationId": "exportItems_1", + "parameters": [ + { + "in": "query", + "name": "query", + "required": false, + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "sort", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation" + } + }, + "summary": "Export list in excel format", + "tags": [ + "Search" + ] + } + }, + "/sample-api/{id}/actions/CAN": { + "post": { + "description": "Sample description", + "operationId": "cancel_1", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "format": "int64", + "type": "integer" + } + } + ], + "responses": { + "201": { + "description": "Cancel executed" + } + }, + "summary": "Cancel", + "tags": [ + "Workflow actions" + ] + } + }, + "/sample-api/{id}/actions/DEL": { + "post": { + "description": "This method should be used when a user wants to delete an entity from the system", + "operationId": "delete_1", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "format": "int64", + "type": "integer" + } + } + ], + "responses": { + "201": { + "description": "Delete executed" + } + }, + "summary": "Delete", + "tags": [ + "Workflow actions" + ] + } + } + }, + "security": [ + ], + "servers": [ + { + "url": "http://sample-server" + } + ] +} \ No newline at end of file diff --git a/core/src/test/resources/issue-857-operation-description-2.json b/core/src/test/resources/issue-857-operation-description-2.json new file mode 100644 index 000000000..690b832ec --- /dev/null +++ b/core/src/test/resources/issue-857-operation-description-2.json @@ -0,0 +1,108 @@ +{ + "components": { + "schemas": { + }, + "securitySchemes": { + } + }, + "info": { + "description": "This is the swagger documentation for sample-api. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). ", + "title": "sample-api", + "version": "3.48.0" + }, + "openapi": "3.1.0", + "paths": { + "/sample-api/export": { + "get": { + "description": "Export into MS Excel", + "operationId": "exportItems_1", + "parameters": [ + { + "in": "query", + "name": "query", + "required": false, + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "sort", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation" + } + }, + "summary": "Export list in excel format", + "tags": [ + "Search" + ] + } + }, + "/sample-api/{id}/actions/CAN": { + "post": { + "description": "Sample description changed", + "operationId": "cancel_1", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "format": "int64", + "type": "integer" + } + } + ], + "responses": { + "201": { + "description": "Cancel executed" + } + }, + "summary": "Cancel", + "tags": [ + "Workflow actions" + ] + } + }, + "/sample-api/{id}/actions/DEL": { + "post": { + "description": "This method should be used when a user wants to delete an entity from the system", + "operationId": "delete_1", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "format": "int64", + "type": "integer" + } + } + ], + "responses": { + "201": { + "description": "Delete executed" + } + }, + "summary": "Delete", + "tags": [ + "Workflow actions" + ] + } + } + }, + "security": [ + ], + "servers": [ + { + "url": "http://sample-server" + } + ] +} \ No newline at end of file