Nested lists are not handled
See original GitHub issueDescribe the bug We have a simple DTO mapping which includes a list objects of the same data type. This is the class:
@Data
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Schema(name = "CourseDraftNode")
public class CourseDraftNodeResponse implements Comparable<CourseDraftNodeResponse> {
@NotNull
private UUID key;
@NotNull
private OffsetDateTime createdAt;
@NotNull
private OffsetDateTime updatedAt;
private UUID parentKey;
@NotNull
private UUID draftKey;
@NotNull
private CourseNodeType type;
@NotNull
private Integer position;
@NotNull
private String title;
private String description;
@NotNull
private List<CourseDraftNodeItemResponse> items = new ArrayList<>();
@NotNull
private List<CourseDraftNodeResponse> children = new ArrayList<>();
@Override
public int compareTo(CourseDraftNodeResponse otherNodeResponse) {
// Sort by parentKey nulls first and then by position
if (Objects.isNull(parentKey) && Objects.nonNull(otherNodeResponse.getParentKey())) {
return -1;
} else if (Objects.nonNull(parentKey) && Objects.isNull(otherNodeResponse.getParentKey())) {
return 1;
} else {
return position.compareTo(otherNodeResponse.getPosition());
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CourseDraftNodeResponse that)) return false;
return getKey().equals(that.getKey());
}
@Override
public int hashCode() {
return Objects.hash(getKey());
}
}
The list children is not included in the generated json. The list items is visible, but not children. We tried other classes and added Lists. Whenever we want to add a list with the same data type as the object to model a tree structure, the list is not present in the generated api specification.
This is how the the class looks like if you inspect it with swagger ui.
If I change the type from List to ArrayList in the response DTO, the list is added to the generated JSON.

In the swagger UI it is displayed as a list of strings… this is really a strange behaviour.

To Reproduce Steps to reproduce the behavior: Create a class which contains a list of the same data type as the class itself. Create a rest endpoint which returns this an object of this class. Inspect the generated JSON and the swagger UI.
-
What version of spring-boot you are using? 2.7.4
-
What modules and versions of springdoc-openapi are you using?
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.6.11</version>
</dependency>
-
What is the actual and the expected result using OpenAPI Description (yml or json)? json
-
Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
@Tag(name = "Course Draft")
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {
@GetMapping
public CourseDraftNodeResponse getCourseDraft() {
return CourseDraftNodeResponse.builder().build();
}
}
Expected behavior The nested list should be added to the json response. Swagger should display not string as data type but the actual object.
Additional context Lombok is used.
Issue Analytics
- State:
- Created 9 months ago
- Reactions:1
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
we are facing the same issue 😦
Annotating the list with @ArraySchema seems to fix the problem. The generated JSON looks fine.