Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ private OlTag ol_changed(List<ChangedOperation> 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())));
Expand Down Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<del class=\"comment\">Sample description</del>");
assertThat(outputStream.toString())
.contains("<span class=\"comment\">Sample description changed</span>");
}

@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("<del class=\"comment\">Sample description</del>");
assertThat(outputStream.toString())
.contains("<span class=\"comment\">Sample description changed</span>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
108 changes: 108 additions & 0 deletions core/src/test/resources/issue-857-operation-description-1.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
108 changes: 108 additions & 0 deletions core/src/test/resources/issue-857-operation-description-2.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}