Skip to content

springdoc does not respect @field:Schema(enumAsRef = true) on a kotlin data class property #3016

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

Open
damiankaplon opened this issue Jun 4, 2025 · 0 comments

Comments

@damiankaplon
Copy link

Good morning, evening!

Having

@RestController
class HelloController {

	@GetMapping("/hello")
	fun hello() = Response(status = Response.Status.SUCCESS)
}

data class Response(@field:Schema(enumAsRef = true) val status: Status) {
	enum class Status {
		SUCCESS,
		ERROR
	}
}

generates response schema ⬇ :

"schemas":{"Response":{"type":"object","properties":{"status":{"type":"string","enum":["SUCCESS","ERROR"]}}}}

I expected ⬇ :

"schemas":{"Response":{"type":"object","properties":{"status":{"$ref":"#/components/schemas/Status"}}},"Status":{"type":"string","enum":["SUCCESS","ERROR"]}}}

It can be achieved annotating an enum class with Schema(enumAsRef = true) but I'd prefer to annotate a data class property instead) 🙏🏼

Here is a minimal, reproducible example

Versions:

                         <groupId>org.springframework.boot</groupId>
		        <artifactId>spring-boot-starter-parent</artifactId>
		        <version>3.5.0</version>

			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
			<version>2.8.0</version>

			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-common</artifactId>
			<version>2.8.0</version>

	                 <groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-maven-plugin</artifactId>
			<version>1.4</version>
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

1 participant