-
-
Notifications
You must be signed in to change notification settings - Fork 566
Description
Describe the bug
I encountered another bug while doing Spring Boot 2 -> 3 migration.
springdoc-openapi-starter-webmvc-ui 2.8.14 is unable to generate schema for LinkedHashSet type. The schema was generated correctly using springdoc-openapi-ui 1.8.0.
To Reproduce
Steps to reproduce the behavior:
main class:
package com.example.demo
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/test")
@SpringBootApplication
class DemoApp {
@GetMapping
fun getTestData(): Foo = Foo(bar = linkedSetOf("test"))
}
// The bug appears to be due to
// 1. Usage of Kotlin
// 2. Usage of LinkedHashSet
data class Foo(
val bar: LinkedHashSet<String>,
)
fun main(args: Array<String>) {
runApplication<DemoApp>(*args)
}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.5.8</version>
<!-- <version>2.7.18</version>-->
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springdoc-visibility-bug</name>
<description>Example showing bug: cannot infer visibility</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
<kotlin.version>2.0.20</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.14</version>
<!-- <artifactId>springdoc-openapi-ui</artifactId>-->
<!-- <version>1.8.0</version>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>Start server. Hit http://localhost:8080/v3/api-docs. Observe exception in logs:
java.lang.IllegalStateException: Cannot infer visibility for inherited open fun clone(): kotlin.Any defined in java.util.LinkedHashSet[JavaMethodDescriptor@61add9f1]
at kotlin.reflect.jvm.internal.impl.descriptors.runtime.components.RuntimeErrorReporter.reportCannotInferVisibility(RuntimeErrorReporter.kt:31) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.load.java.components.DescriptorResolverUtils$1$1.invoke(DescriptorResolverUtils.java:79) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.load.java.components.DescriptorResolverUtils$1$1.invoke(DescriptorResolverUtils.java:76) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.resolve.OverridingUtil.resolveUnknownVisibilityForMember(OverridingUtil.java:909) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.load.java.components.DescriptorResolverUtils$1.addFakeOverride(DescriptorResolverUtils.java:76) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.resolve.OverridingUtil.createAndBindFakeOverride(OverridingUtil.java:737) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.resolve.OverridingUtil.createAndBindFakeOverrides(OverridingUtil.java:579) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
at kotlin.reflect.jvm.internal.impl.resolve.OverridingUtil.generateOverridesInFunctionGroup(OverridingUtil.java:500) ~[kotlin-reflect-2.0.20.jar:2.0.20-release-360]
<rest omitted>
For comparison, here are the generated schemas using 1.8.0 and 2.8.14.
springdoc-openapi-ui 1.8.0:
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"demo-app"
],
"operationId": "getTestData",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Foo"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Foo": {
"type": "object",
"properties": {
"bar": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
}springdoc-openapi-starter-webmvc-ui 2.8.14:
{
"openapi": "3.1.0",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"demo-app"
],
"operationId": "getTestData",
"responses": {
"200": {
"description": "OK",
"content": {}
}
}
}
}
},
"components": {}
}-
What version of spring-boot you are using?
3.5.8 -
What modules and versions of springdoc-openapi are you using?
springdoc-openapi-starter-webmvc-ui, 2.8.14 -
What is the actual and the expected result using OpenAPI Description (yml or json)?
Actual: response type is missing in schema
Expected: response type is included in schema -
Provide with a sample code (HelloController) or Test that reproduces the problem
See above.
Expected behavior
- A clear and concise description of what you expected to happen.
- What is the expected result using OpenAPI Description (yml or json)?
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.