From 0d3051157e3097b9220a898594df3a6bc0dd8097 Mon Sep 17 00:00:00 2001 From: Inf1mum Date: Wed, 18 Nov 2026 19:00:03 +0300 Subject: [PATCH] Fix #523: report enum and property changes for repeated schemas in markdown output The markdown renderer kept a global set of already-rendered schemas. Swagger Schema implements equals/hashCode by value, so any second schema with identical content (or a repeated reference to the same component) had its whole subtree silently dropped from the report. Replace the global set with an identity-based set of the schemas on the current recursion path: recursive definitions still terminate, while repeated references and value-identical subtrees are now fully reported. Signed-off-by: Inf1mum --- .../core/output/MarkdownRender.java | 30 ++++--- .../core/output/MarkdownRenderTest.java | 39 +++++++++ core/src/test/resources/issue-523-enum-1.yaml | 70 ++++++++++++++++ core/src/test/resources/issue-523-enum-2.yaml | 80 +++++++++++++++++++ .../src/test/resources/issue-523-props-1.yaml | 28 +++++++ .../src/test/resources/issue-523-props-2.yaml | 69 ++++++++++++++++ 6 files changed, 303 insertions(+), 13 deletions(-) create mode 100644 core/src/test/resources/issue-523-enum-1.yaml create mode 100644 core/src/test/resources/issue-523-enum-2.yaml create mode 100644 core/src/test/resources/issue-523-props-1.yaml create mode 100644 core/src/test/resources/issue-523-props-2.yaml diff --git a/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java b/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java index 531fd3809..8fb510750 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/output/MarkdownRender.java @@ -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; @@ -42,7 +43,7 @@ public class MarkdownRender implements Render { protected RefPointer> refPointer = new RefPointer<>(RefType.SCHEMAS); protected ChangedOpenApi diff; - protected Set> handledSchemas = new HashSet<>(); + protected Set> visitingSchemas = Collections.newSetFromMap(new IdentityHashMap<>()); /** * A parameter which indicates whether or not metadata (summary and metadata) changes should be * logged in the changelog file. @@ -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(), @@ -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) { diff --git a/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java b/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java index 597882105..1c108e129 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/output/MarkdownRenderTest.java @@ -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; + } } diff --git a/core/src/test/resources/issue-523-enum-1.yaml b/core/src/test/resources/issue-523-enum-1.yaml new file mode 100644 index 000000000..5c402765c --- /dev/null +++ b/core/src/test/resources/issue-523-enum-1.yaml @@ -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 diff --git a/core/src/test/resources/issue-523-enum-2.yaml b/core/src/test/resources/issue-523-enum-2.yaml new file mode 100644 index 000000000..0ed2d0145 --- /dev/null +++ b/core/src/test/resources/issue-523-enum-2.yaml @@ -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 diff --git a/core/src/test/resources/issue-523-props-1.yaml b/core/src/test/resources/issue-523-props-1.yaml new file mode 100644 index 000000000..cadc52eb6 --- /dev/null +++ b/core/src/test/resources/issue-523-props-1.yaml @@ -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: {} diff --git a/core/src/test/resources/issue-523-props-2.yaml b/core/src/test/resources/issue-523-props-2.yaml new file mode 100644 index 000000000..38cd53f0f --- /dev/null +++ b/core/src/test/resources/issue-523-props-2.yaml @@ -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"