Skip to content

fix(594): fix console rendering #595

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

Merged
merged 2 commits into from
Dec 16, 2023
Merged
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 @@ -47,6 +47,7 @@ public void render(ChangedOpenApi diff, OutputStreamWriter outputStreamWriter) {
List<ChangedOperation> changedOperations = diff.getChangedOperations();
ol_changed(changedOperations, outputStreamWriter);

safelyAppend(outputStreamWriter, title("Result"));
safelyAppend(
outputStreamWriter,
StringUtils.center(
Expand Down Expand Up @@ -76,6 +77,8 @@ private void ol_changed(
String desc =
Optional.ofNullable(operation.getSummary()).map(ChangedMetadata::getRight).orElse("");

safelyAppend(outputStreamWriter, itemEndpoint(method, pathUrl, desc));

if (result(operation.getParameters()).isDifferent()) {
safelyAppend(outputStreamWriter, StringUtils.repeat(' ', 2));
safelyAppend(outputStreamWriter, "Parameter:");
Expand All @@ -94,7 +97,6 @@ private void ol_changed(
safelyAppend(outputStreamWriter, System.lineSeparator());
safelyAppend(outputStreamWriter, ul_response(operation.getApiResponses()));
}
safelyAppend(outputStreamWriter, itemEndpoint(method, pathUrl, desc));
}
}

Expand Down Expand Up @@ -279,10 +281,10 @@ private String li_changedParam(ChangedParameter changeParam) {
}
}

private String listEndpoints(
private void listEndpoints(
List<Endpoint> endpoints, String title, OutputStreamWriter outputStreamWriter) {
if (null == endpoints || endpoints.isEmpty()) {
return "";
return;
}
StringBuilder sb = new StringBuilder();
sb.append(title(title));
Expand All @@ -291,7 +293,8 @@ private String listEndpoints(
itemEndpoint(
endpoint.getMethod().toString(), endpoint.getPathUrl(), endpoint.getSummary()));
}
return sb.append(System.lineSeparator()).toString();

safelyAppend(outputStreamWriter, sb.append(System.lineSeparator()).toString());
}

private String itemEndpoint(String method, String path, String desc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public void renderDoesNotFailWhenPropertyHasBeenRemoved() {
ConsoleRender render = new ConsoleRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("missing_property_1.yaml", "missing_property_2.yaml");
ChangedOpenApi diff = OpenApiCompare.fromLocations("missing_property_1.yaml", "missing_property_2.yaml");
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).isNotBlank();
}
Expand All @@ -30,4 +29,50 @@ public void renderDoesNotFailWhenHTTPStatusCodeIsRange() {
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).isNotBlank();
}

@Test
public void renderShowsWhatsDeletedSectionWhenEndpointIsDeleted() {
ConsoleRender render = new ConsoleRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("delete_endpoint_1.yaml", "delete_endpoint_2.yaml");
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).contains("What's Deleted");
}

@Test
public void renderShowsWhatsNewSectionWhenEndpointIsAdded() {
ConsoleRender render = new ConsoleRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("add_endpoint_1.yaml", "add_endpoint_2.yaml");
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).contains("What's New");
}

@Test
public void renderShowsWhatsDeprecatedSectionWhenEndpointIsDeprecated() {
ConsoleRender render = new ConsoleRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("deprecate_endpoint_1.yaml", "deprecate_endpoint_2.yaml");
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).contains("What's Deprecated");
}

@Test
public void renderShowsWhatsChangedSectionWithCorrectFormattingWhenEndpointIsChanged() {
ConsoleRender render = new ConsoleRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("change_endpoint_1.yaml", "change_endpoint_2.yaml");
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString())
.contains("What's Changed")
.containsSubsequence("- GET /widgets", "Parameter:", "- Changed query-param-1 in query");
}
}
35 changes: 35 additions & 0 deletions core/src/test/resources/add_endpoint_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
`special-key` to test the authorization filters.
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pet/{petId}:
get:
tags:
- pet
summary: gets a pet by id
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
responses:
'405':
description: Invalid input
53 changes: 53 additions & 0 deletions core/src/test/resources/add_endpoint_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
`special-key` to test the authorization filters.
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pet/{petId}:
get:
tags:
- pet
summary: gets a pet by id
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
responses:
'405':
description: Invalid input
/pet/{petId2}:
post:
tags:
- pet
summary: deletes a pet
description: ''
operationId: deletePet
deprecated: true
parameters:
- name: petId2
in: path
description: Pet ID to delete
required: true
schema:
type: integer
responses:
'405':
description: Invalid input
29 changes: 29 additions & 0 deletions core/src/test/resources/change_endpoint_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: 3.0.0
info:
description: myDesc
title: myTitle
version: 1.0.0
paths:
/widgets:
get:
operationId: listWidgets
parameters:
- name: query-param-1
in: query
required: true
schema:
type: string
- name: query-param-2
in: query
style: form
explode: true
allowEmptyValue: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: string
30 changes: 30 additions & 0 deletions core/src/test/resources/change_endpoint_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: 3.0.0
info:
description: myDesc
title: myTitle
version: 1.0.0
paths:
/widgets:
get:
operationId: listWidgets
parameters:
- name: query-param-1
in: query
allowEmptyValue: true
required: false
schema:
type: string
- name: query-param-2
in: query
style: form
explode: true
allowEmptyValue: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: string
52 changes: 52 additions & 0 deletions core/src/test/resources/delete_endpoint_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
`special-key` to test the authorization filters.
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pet/{petId}:
get:
tags:
- pet
summary: gets a pet by id
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
responses:
'405':
description: Invalid input
/pet/{petId2}:
get:
tags:
- pet
summary: gets a pet by id
description: ''
operationId: updatePetWithForm
parameters:
- name: petId2
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
responses:
'405':
description: Invalid input
35 changes: 35 additions & 0 deletions core/src/test/resources/delete_endpoint_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
`special-key` to test the authorization filters.
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pet/{petId}:
get:
tags:
- pet
summary: gets a pet by id
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
responses:
'405':
description: Invalid input
Loading