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 @@ -13,7 +13,8 @@
import io.swagger.v3.oas.models.responses.ApiResponse;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class MarkdownRender implements Render {

protected RefPointer<Schema<?>> refPointer = new RefPointer<>(RefType.SCHEMAS);
protected ChangedOpenApi diff;
protected Set<Schema<?>> handledSchemas = new HashSet<>();
protected Set<Schema<?>> visitingSchemas = Collections.newSetFromMap(new IdentityHashMap<>());

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 removes the existing protected handledSchemas field from a public renderer, breaking subclasses that access it. Preserve handledSchemas as the field name (or provide a compatibility alias) while changing its set implementation.

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/MarkdownRender.java, line 46:

<comment>This removes the existing protected `handledSchemas` field from a public renderer, breaking subclasses that access it. Preserve `handledSchemas` as the field name (or provide a compatibility alias) while changing its set implementation.</comment>

<file context>
@@ -42,7 +43,7 @@ public class MarkdownRender implements Render {
   protected RefPointer<Schema<?>> refPointer = new RefPointer<>(RefType.SCHEMAS);
   protected ChangedOpenApi diff;
-  protected Set<Schema<?>> handledSchemas = new HashSet<>();
+  protected Set<Schema<?>> visitingSchemas = Collections.newSetFromMap(new IdentityHashMap<>());
   /**
    * A parameter which indicates whether or not metadata (summary and metadata) changes should be
</file context>
Suggested change
protected Set<Schema<?>> visitingSchemas = Collections.newSetFromMap(new IdentityHashMap<>());
protected Set<Schema<?>> handledSchemas = Collections.newSetFromMap(new IdentityHashMap<>());
protected Set<Schema<?>> visitingSchemas = handledSchemas;

/**
* A parameter which indicates whether or not metadata (summary and metadata) changes should be
* logged in the changelog file.
Expand All @@ -51,7 +52,7 @@ public class MarkdownRender implements Render {

public void render(ChangedOpenApi diff, OutputStreamWriter outputStreamWriter) {
this.diff = diff;
this.handledSchemas.clear();
this.visitingSchemas.clear();

apiTitle(
diff.getNewSpecOpenApi().getInfo().getTitle(),
Expand Down Expand Up @@ -381,17 +382,20 @@ protected String schema(int deepness, ComposedSchema schema, DiffContext context
}

protected String schema(int deepness, Schema schema, DiffContext context) {
if (handledSchemas.contains(schema)) return "";
handledSchemas.add(schema);
StringBuilder sb = new StringBuilder();
sb.append(listItem(deepness, "Enum", schema.getEnum()));
sb.append(properties(deepness, "Property", schema.getProperties(), true, context));
if (schema instanceof ComposedSchema) {
sb.append(schema(deepness, (ComposedSchema) schema, context));
} else if (schema instanceof ArraySchema) {
sb.append(items(deepness, resolve(((ArraySchema) schema).getItems()), context));
if (!visitingSchemas.add(schema)) return "";
try {
StringBuilder sb = new StringBuilder();
sb.append(listItem(deepness, "Enum", schema.getEnum()));
sb.append(properties(deepness, "Property", schema.getProperties(), true, context));
if (schema instanceof ComposedSchema) {
sb.append(schema(deepness, (ComposedSchema) schema, context));
} else if (schema instanceof ArraySchema) {
sb.append(items(deepness, resolve(((ArraySchema) schema).getItems()), context));
}
return sb.toString();
} finally {
visitingSchemas.remove(schema);
}
return sb.toString();
}

protected String items(int deepness, ChangedSchema schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,43 @@ public void issue870_renderDoesNotFailWhenSchemaIsNullButExampleChanged() {
render.render(diff, outputStreamWriter);
assertThat(outputStream.toString()).isNotBlank();
}

@Test
public void issue523_enumValuesAreReportedForRepeatedIdenticalSchemas() {
MarkdownRender render = new MarkdownRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("issue-523-enum-1.yaml", "issue-523-enum-2.yaml");
render.render(diff, outputStreamWriter);
String markdown = outputStream.toString();
assertThat(countOccurrences(markdown, "`none`")).isEqualTo(2);
assertThat(countOccurrences(markdown, "`enabled`")).isEqualTo(2);
assertThat(countOccurrences(markdown, "`push`")).isEqualTo(2);
assertThat(countOccurrences(markdown, "`disabled`")).isEqualTo(2);
}

@Test
public void issue523_propertiesAreReportedForRepeatedIdenticalSchemas() {
MarkdownRender render = new MarkdownRender();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
ChangedOpenApi diff =
OpenApiCompare.fromLocations("issue-523-props-1.yaml", "issue-523-props-2.yaml");
render.render(diff, outputStreamWriter);
String markdown = outputStream.toString();
assertThat(countOccurrences(markdown, "`partiallyPopulated`")).isEqualTo(2);
assertThat(countOccurrences(markdown, "`additionalAttributes`")).isEqualTo(2);
assertThat(countOccurrences(markdown, "`type`")).isEqualTo(2);
}

private static int countOccurrences(String haystack, String needle) {
int count = 0;
int index = 0;
while ((index = haystack.indexOf(needle, index)) != -1) {
count++;
index += needle.length();
}
return count;
}
}
70 changes: 70 additions & 0 deletions core/src/test/resources/issue-523-enum-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
openapi: 3.0.1
info:
title: issue 523 enum
version: "1.0"
paths:
/check/api/Id/Exp/{ExpId}:
get:
responses:
default:
content:
application/json:
schema:
$ref: "#/components/schemas/ExpRO"
components:
schemas:
ExpRO:
type: object
properties:
data:
$ref: "#/components/schemas/ExpDataRO"
ExpDataRO:
type: object
properties:
id:
type: string
type:
type: string
enum:
- tpeExpectations
attributes:
$ref: "#/components/schemas/ExpAttributesRO"
ExpAttributesRO:
type: object
properties:
Terminations:
type: array
items:
$ref: "#/components/schemas/TerminationRO"
TerminationRO:
type: object
properties:
nniNetwork:
$ref: "#/components/schemas/NetworkRO"
ponConnection:
$ref: "#/components/schemas/PonConnectionRO"
NetworkRO:
type: object
properties:
tagAction:
type: string
enum:
- none
- pop
- push
- stamp
floodingLink:
type: string
enum:
- enabled
- disabled
PonConnectionRO:
type: object
properties:
tagAction:
type: string
enum:
- none
- pop
- push
- stamp
80 changes: 80 additions & 0 deletions core/src/test/resources/issue-523-enum-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
openapi: 3.0.1
info:
title: issue 523 enum
version: "1.0"
paths:
/check/api/Id/Exp/{ExpId}:
get:
responses:
default:
content:
application/json:
schema:
$ref: "#/components/schemas/ExpRO"
components:
schemas:
ExpRO:
type: object
properties:
data:
$ref: "#/components/schemas/ExpDataRO"
ExpDataRO:
type: object
properties:
id:
type: string
type:
type: string
enum:
- tpeExpectations
attributes:
$ref: "#/components/schemas/ExpAttributesRO"
ExpAttributesRO:
type: object
properties:
Terminations:
type: array
items:
$ref: "#/components/schemas/TerminationRO"
TerminationRO:
type: object
properties:
NetworkConnectionPackage:
$ref: "#/components/schemas/NetworkConnectionRO"
ponConnectionPackage:
$ref: "#/components/schemas/PonConnectionRO"
datalinkPackage:
$ref: "#/components/schemas/DatalinkRO"
NetworkConnectionRO:
type: object
properties:
tagAction:
type: string
enum:
- none
- pop
- push
- stamp
floodingLink:
type: string
enum:
- enabled
- disabled
PonConnectionRO:
type: object
properties:
tagAction:
type: string
enum:
- none
- pop
- push
- stamp
DatalinkRO:
type: object
properties:
adminState:
type: string
enum:
- enabled
- disabled
28 changes: 28 additions & 0 deletions core/src/test/resources/issue-523-props-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.1
info:
title: issue 523 properties
version: "1.0"
paths:
/check/API:
get:
responses:
default:
content:
application/json:
schema:
$ref: "#/components/schemas/ExpAPIRO"
components:
schemas:
ExpAPIRO:
type: object
properties:
data:
$ref: "#/components/schemas/ExpAPIDataRO"
ExpAPIDataRO:
type: object
properties:
relationships:
$ref: "#/components/schemas/ExpAPIRelationshipsRO"
ExpAPIRelationshipsRO:
type: object
properties: {}
69 changes: 69 additions & 0 deletions core/src/test/resources/issue-523-props-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
openapi: 3.0.1
info:
title: issue 523 properties
version: "1.0"
paths:
/check/API:
get:
responses:
default:
content:
application/json:
schema:
$ref: "#/components/schemas/ExpAPIRO"
components:
schemas:
ExpAPIRO:
type: object
properties:
data:
$ref: "#/components/schemas/ExpAPIDataRO"
ExpAPIDataRO:
type: object
properties:
relationships:
$ref: "#/components/schemas/ExpAPIRelationshipsRO"
ExpAPIRelationshipsRO:
type: object
properties:
linkedTpes:
$ref: "#/components/schemas/OneToManyRelationshipRO"
shelfNetworkConstruct:
$ref: "#/components/schemas/OneToOneRelationshipRO"
OneToManyRelationshipRO:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/RelationshipDataRO"
meta:
$ref: "#/components/schemas/RelationshipMetaDataRO"
RelationshipDataRO:
type: object
properties:
type:
type: string
id:
type: string
attributes:
$ref: "#/components/schemas/RelationshipAttributesRO"
RelationshipAttributesRO:
type: object
properties:
additionalAttributes:
$ref: "#/components/schemas/AdditionalAttributesRO"
AdditionalAttributesRO:
type: object
RelationshipMetaDataRO:
type: object
properties:
partiallyPopulated:
type: boolean
OneToOneRelationshipRO:
type: object
properties:
data:
$ref: "#/components/schemas/RelationshipDataRO"
meta:
$ref: "#/components/schemas/RelationshipMetaDataRO"