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 @@ -15,6 +15,7 @@
import org.apache.commons.lang3.StringUtils;
import org.openapitools.openapidiff.core.exception.RendererException;
import org.openapitools.openapidiff.core.model.*;
import org.openapitools.openapidiff.core.model.schema.ChangedEnum;
import org.openapitools.openapidiff.core.model.schema.ChangedOperationId;
import org.openapitools.openapidiff.core.utils.RefPointer;
import org.openapitools.openapidiff.core.utils.RefType;
Expand Down Expand Up @@ -197,6 +198,9 @@ private String incompatibilities(String propName, final ChangedSchema schema) {
String type = type(schema.getOldSchema()) + " -> " + type(schema.getNewSchema());
sb.append(property(propName, "Changed property type", type));
}
if (schema.getEnumeration() != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This prints every enum change inside the 'Broken compatibility' block, including directions that are compatible for this context. For example, a response enum value removed next to a missing property would be reported as 'Removed enum value', though that removal does not break compatibility. Filter by direction, for example by checking changedEnum.isItemsChanged() per side and the request/response context.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At core/src/main/java/org/openapitools/openapidiff/core/output/ConsoleRender.java, line 201:

<comment>This prints every enum change inside the 'Broken compatibility' block, including directions that are compatible for this context. For example, a response enum value removed next to a missing property would be reported as 'Removed enum value', though that removal does not break compatibility. Filter by direction, for example by checking `changedEnum.isItemsChanged()` per side and the request/response context.</comment>

<file context>
@@ -197,6 +198,9 @@ private String incompatibilities(String propName, final ChangedSchema schema) {
       String type = type(schema.getOldSchema()) + " -> " + type(schema.getNewSchema());
       sb.append(property(propName, "Changed property type", type));
     }
+    if (schema.getEnumeration() != null) {
+      sb.append(enumValues(propName, schema.getEnumeration()));
+    }
</file context>

sb.append(enumValues(propName, schema.getEnumeration()));
}
String prefix = propName.isEmpty() ? "" : propName + ".";
sb.append(
properties(prefix, "Missing property", schema.getMissingProperties(), schema.getContext()));
Expand All @@ -210,6 +214,22 @@ private String items(String propName, ChangedSchema schema) {
return incompatibilities(propName + "[n]", schema);
}

private String enumValues(String propName, ChangedEnum<?> changedEnum) {
StringBuilder sb = new StringBuilder();
String prefix = propName.isEmpty() ? "" : propName + " ";
changedEnum
.getIncreased()
.forEach(value -> sb.append(enumValue("Added enum value", prefix + value)));
changedEnum
.getMissing()
.forEach(value -> sb.append(enumValue("Removed enum value", prefix + value)));
return sb.toString();
}

private String enumValue(String title, String value) {
return String.format("%s%s: %s%n", StringUtils.repeat(' ', 10), title, value);
}

private String properties(
String propPrefix, String title, Map<String, Schema<?>> properties, DiffContext context) {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public void renderShowsWhatsChangedSectionWithCorrectFormattingWhenEndpointIsCha
.containsSubsequence("- GET /widgets", "Parameter:", "- Changed query-param-1 in query");
}

@Test
public void renderShowsChangedEnumValuesWhenResponseEnumValueIsAdded() {
ConsoleRender render = new ConsoleRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff = OpenApiCompare.fromLocations("enum_diff_1.yaml", "enum_diff_2.yaml");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This test only covers the added-enum branch. ConsoleRender.enumValues also emits Removed enum value lines, which the PR description calls out, but no console test asserts that output. Add a case with a removed value (for example, swap the fixture order) and assert the Removed enum value: [n].someProperty ... line.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At core/src/test/java/org/openapitools/openapidiff/core/output/ConsoleRenderTest.java, line 85:

<comment>This test only covers the added-enum branch. `ConsoleRender.enumValues` also emits `Removed enum value` lines, which the PR description calls out, but no console test asserts that output. Add a case with a removed value (for example, swap the fixture order) and assert the `Removed enum value: [n].someProperty ...` line.</comment>

<file context>
@@ -77,6 +77,18 @@ public void renderShowsWhatsChangedSectionWithCorrectFormattingWhenEndpointIsCha
+    ConsoleRender render = new ConsoleRender();
+    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
+    ChangedOpenApi diff = OpenApiCompare.fromLocations("enum_diff_1.yaml", "enum_diff_2.yaml");
+    render.render(diff, outputStreamWriter);
+    assertThat(outputStream.toString())
</file context>

render.render(diff, outputStreamWriter);
assertThat(outputStream.toString())
.containsSubsequence(
"Schema: Broken compatibility", "Added enum value: [n].someProperty ENUM_VALUE_3");
}

@Test
public void issue870_renderDoesNotFailWhenSchemaIsNullButExampleChanged() {
ConsoleRender render = new ConsoleRender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public void renderDoesNotFailWhenHTTPStatusCodeIsRange() {
assertThat(outputStream.toString()).isNotBlank();
}

@Test
public void renderShowsChangedEnumValuesWhenResponseEnumValueIsAdded() {
MarkdownRender render = new MarkdownRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff = OpenApiCompare.fromLocations("enum_diff_1.yaml", "enum_diff_2.yaml");
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).containsSubsequence("Added enum value", "`ENUM_VALUE_3`");
}

@Test
public void issue870_renderDoesNotFailWhenSchemaIsNullButExampleChanged() {
MarkdownRender render = new MarkdownRender();
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/resources/enum_diff_1.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:
/resources1/{id}/resources2:
get:
operationId: listResources2
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
type: object
properties:
someProperty:
type: string
enum:
- ENUM_VALUE_1
- ENUM_VALUE_2
31 changes: 31 additions & 0 deletions core/src/test/resources/enum_diff_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.0
info:
description: myDesc
title: myTitle
version: 1.0.0
paths:
/resources1/{id}/resources2:
get:
operationId: listResources2
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
type: object
properties:
someProperty:
type: string
enum:
- ENUM_VALUE_1
- ENUM_VALUE_2
- ENUM_VALUE_3