Skip to content
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

Fix: Markdown and Console renderer fail when processing range HTTP status code e. g. '2XX' #397

Merged
merged 3 commits into from
Jul 25, 2022
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 @@ -118,7 +118,7 @@ private String ul_response(ChangedApiResponse changedApiResponse) {
private String itemResponse(String title, String code) {
StringBuilder sb = new StringBuilder();
String status = "";
if (!code.equals("default")) {
if (!code.equals("default") && !code.matches("[1-5]XX")) {
status = HttpStatus.getReasonPhrase(Integer.parseInt(code));
}
sb.append(StringUtils.repeat(' ', 4))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected String itemResponse(String code, ChangedResponse response) {
protected String itemResponse(String title, String code, String description) {
StringBuilder sb = new StringBuilder();
String status = "";
if (!code.equals("default")) {
if (!code.equals("default") && !code.matches("[1-5]XX")) {
status = HttpStatus.getReasonPhrase(Integer.parseInt(code));
}
sb.append(format("%s : **%s %s**\n", title, code, status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public void renderDoesNotFailWhenPropertyHasBeenRemoved() {
OpenApiCompare.fromLocations("missing_property_1.yaml", "missing_property_2.yaml");
assertThat(render.render(diff)).isNotBlank();
}

@Test
public void renderDoesNotFailWhenHTTPStatusCodeIsRange() {
ConsoleRender render = new ConsoleRender();
ChangedOpenApi diff =
OpenApiCompare.fromLocations("range_statuscode_1.yaml", "range_statuscode_2.yaml");
assertThat(render.render(diff)).isNotBlank();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ public void renderDoesNotCauseStackOverflowWithRecursiveDefinitions() {
ChangedOpenApi diff = OpenApiCompare.fromLocations("recursive_old.yaml", "recursive_new.yaml");
assertThat(render.render(diff)).isNotBlank();
}

@Test
public void renderDoesNotFailWhenHTTPStatusCodeIsRange() {
MarkdownRender render = new MarkdownRender();
ChangedOpenApi diff =
OpenApiCompare.fromLocations("range_statuscode_1.yaml", "range_statuscode_2.yaml");
assertThat(render.render(diff)).isNotBlank();
}
}
10 changes: 10 additions & 0 deletions core/src/test/resources/range_statuscode_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
openapi: 3.0.0
info:
title: Projects API
version: 1.0.0
paths:
/pet/:
get:
responses:
"405":
description: "Invalid input"
10 changes: 10 additions & 0 deletions core/src/test/resources/range_statuscode_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
openapi: 3.0.0
info:
title: Projects API
version: 1.0.0
paths:
/pet/:
get:
responses:
"4XX":
description: "Invalid input"