Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"springdoc-openapi-starter-webflux-ui" for sprint boot 3.x can't parse nested POJO well, but "springdoc-openapi-webflux-ui" for spring boot 2.x works well. #2949

Closed
softenwareness opened this issue Mar 26, 2025 · 2 comments

Comments

@softenwareness
Copy link

softenwareness commented Mar 26, 2025

Describe the bug
It was working for nested POJO as openAPI request or response definition before(Spring boot 2.7.18), but upgrade to spring boot 3.x, not working any more, throw exception.

To Reproduce
Steps to reproduce the behavior:

  1. To define a POJO
@Data
public class FieldDescriptor {
    private String name;
    private String type;
    @ArraySchema(schema = @Schema(name = "fields", implementation = FieldDescriptor.class, ref = "FieldDescriptor"))
    private List<FieldDescriptor> fields = new ArrayList<>();

}

//To use it to Controller
`@Tag(name = "Demo")
@RestController("demo/api")
@RequiredArgsConstructor
public class DemoController {

    @GetMapping("/get")
    public Mono<ResponseEntity<FieldDescriptor>> get() {
        FieldDescriptor fieldDescriptor = new FieldDescriptor();
        fieldDescriptor.setName("fields");
        fieldDescriptor.setType("String");
        FieldDescriptor subFieldDescriptor = new FieldDescriptor();
        subFieldDescriptor.setName("sub");
        subFieldDescriptor.setType("Integer");

        fieldDescriptor.getFields().add(subFieldDescriptor);

       return Mono.just(ResponseEntity.ok(fieldDescriptor));
    }
}

pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.4.4</version>
<!--		<version>2.7.18</version>-->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>17</java.version>

	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>
		<!-- For Spring Boot 3.4.x, throw exception -->
		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
			<version>2.8.6</version>
		</dependency>
		<!-- For Spring Boot 2.7.18, it works well -->
<!--		<dependency>-->
<!--			<groupId>org.springdoc</groupId>-->
<!--			<artifactId>springdoc-openapi-webflux-ui</artifactId>-->
<!--			<version>1.8.0</version>-->
<!--		</dependency>-->

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>provided</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>
  • What version of spring-boot you are using? 3.4.4
  • What modules and versions of springdoc-openapi are you using? 2.8.6
  • What is the actual and the expected result using OpenAPI Description (yml or json)?

Throw Exception

Warning

java.lang.StackOverflowError: null
at org.springdoc.core.converters.WebFluxSupportConverter.resolve(WebFluxSupportConverter.java:89) ~[springdoc-openapi-starter-common-2.8.6.jar:2.8.6]
at org.springdoc.core.converters.AdditionalModelsConverter.resolve(AdditionalModelsConverter.java:163) ~[springdoc-openapi-starter-common-2.8.6.jar:2.8.6]
at org.springdoc.core.converters.FileSupportConverter.resolve(FileSupportConverter.java:72) ~[springdoc-openapi-starter-common-2.8.6.jar:2.8.6]
at org.springdoc.core.converters.ResponseSupportConverter.resolve(ResponseSupportConverter.java:84) ~[springdoc-openapi-starter-common-2.8.6.jar:2.8.6]
at org.springdoc.core.converters.SchemaPropertyDeprecatingConverter.resolve(SchemaPropertyDeprecatingConverter.java:95) ~[springdoc-openapi-starter-common-2.8.6.jar:2.8.6]
....

Expected behavior
For below nested POJO, can work well .
It was working well for

@Data
public class FieldDescriptor {
    private String name;

    private String type;

    @ArraySchema(schema = @Schema(name = "fields", implementation = FieldDescriptor.class, ref = "FieldDescriptor"))
    private List<FieldDescriptor> fields = new ArrayList<>();

}
  • Provide with a sample code (HelloController) or Test that reproduces the problem
    Additional context
    Please download below zip file and have a try.
    demo.zip
@softenwareness softenwareness changed the title ava.lang.StackOverflowError exception for nested POJO as request or response "springdoc-openapi-starter-webflux-ui" for sprint boot 3.x can't parse nested POJO well, but "springdoc-openapi-webflux-ui" for spring boot 2.x works well. Mar 26, 2025
@bnasslahsen
Copy link
Collaborator

@softenwareness,

v1 of springdoc was only covering OAS 3.0
If you use same version of OpenAPI by setting springdoc.api-docs.version=openapi_3_0, generation will work.

The issue you are getting is bug in swagger-core, that you should report.

Use this sample and will get StackOverflowError.

ModelConverters.getInstance(true)
				.resolveAsResolvedSchema(
						new AnnotatedType(FieldDescriptor.class));

Also the following syntax, avoids the issue:

  @ArraySchema(schema = @Schema(name = "fields", ref = "FieldDescriptor"))
   private List<FieldDescriptor> fields = new ArrayList<>();

@softenwareness
Copy link
Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants