Skip to content

Commit 49caebc

Browse files
fix: retain identical recursive properties (#5232)
Co-authored-by: Daniel Kmiecik <daniel.kmiecik@smartbear.com>
1 parent a90289f commit 49caebc

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

modules/swagger-core/src/main/java/io/swagger/v3/core/converter/AnnotatedType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,13 @@ public boolean equals(Object o) {
277277
AnnotatedType that = (AnnotatedType) o;
278278
List<Annotation> thisAnnotations = getProcessedAnnotations(this.ctxAnnotations);
279279
List<Annotation> thatAnnotations = getProcessedAnnotations(that.ctxAnnotations);
280+
String thisParentName = this.parent != null ? this.parent.getName() : null;
281+
String thatParentName = that.parent != null ? that.parent.getName() : null;
282+
280283
return includePropertiesWithoutJSONView == that.includePropertiesWithoutJSONView &&
281284
schemaProperty == that.schemaProperty &&
282285
isSubtype == that.isSubtype &&
286+
(!schemaProperty || Objects.equals(thisParentName, thatParentName)) &&
283287
Objects.equals(type, that.type) &&
284288
Objects.equals(thisAnnotations, thatAnnotations) &&
285289
Objects.equals(jsonViewAnnotation, that.jsonViewAnnotation) &&
@@ -289,7 +293,8 @@ public boolean equals(Object o) {
289293
@Override
290294
public int hashCode() {
291295
List<Annotation> processedAnnotations = getProcessedAnnotations(this.ctxAnnotations);
292-
return Objects.hash(type, jsonViewAnnotation, includePropertiesWithoutJSONView, processedAnnotations, schemaProperty, isSubtype, schemaProperty ? propertyName : null);
296+
String parentName = (schemaProperty && this.parent != null) ? this.parent.getName() : null;
297+
return Objects.hash(type, jsonViewAnnotation, includePropertiesWithoutJSONView, processedAnnotations, schemaProperty, isSubtype, schemaProperty ? propertyName : null, parentName);
293298
}
294299

295300
private boolean processableAnnotationPackage(Package pkg) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.swagger.v3.core.resolving;
2+
3+
import io.swagger.v3.core.converter.ModelConverters;
4+
import io.swagger.v3.oas.models.media.Schema;
5+
import org.testng.annotations.Test;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
12+
13+
import static org.testng.Assert.assertNotNull;
14+
import static org.testng.Assert.assertEquals;
15+
16+
public class RecursivePropertyMissingTest {
17+
18+
static class WrapperDTO {
19+
@JsonProperty("nodes")
20+
@JsonPropertyDescription("Child nodes")
21+
public List<TestNodeDTO> nodes;
22+
}
23+
24+
static class TestNodeDTO {
25+
@JsonProperty("name")
26+
public String name;
27+
28+
@JsonProperty("nodes")
29+
@JsonPropertyDescription("Child nodes")
30+
public List<TestNodeDTO> nodes;
31+
}
32+
33+
@Test
34+
public void testRecursivePropertyNotMissing() {
35+
Map<String, Schema> schemas = ModelConverters.getInstance().readAll(WrapperDTO.class);
36+
Schema testNodeDTOSchema = schemas.get("TestNodeDTO");
37+
assertNotNull(testNodeDTOSchema);
38+
39+
Map<String, Schema> properties = testNodeDTOSchema.getProperties();
40+
assertNotNull(properties, "Properties should not be null");
41+
assertNotNull(properties.get("nodes"), "The 'nodes' property is missing from TestNodeDTO schema");
42+
}
43+
}

modules/swagger-core/src/test/resources/converting/ArrayOfSubclassTest_expected30.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@
7979
},
8080
"friend" : {
8181
"type" : "string"
82+
},
83+
"baseArray" : {
84+
"minItems" : 0,
85+
"uniqueItems" : true,
86+
"type" : "array",
87+
"description" : "Thingy",
88+
"items" : {
89+
"$ref" : "#/components/schemas/Base"
90+
}
8291
}
8392
},
8493
"description" : "The SubB class"

0 commit comments

Comments
 (0)